Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <array>
- using namespace std;
- ifstream cin("easyocr.in");
- ofstream cout("easyocr.out");
- #define UP 0
- #define DOWN 1
- #define LEFT 2
- #define RIGHT 3
- #define LEFT_DOWN 4
- char mat[1001][1001];
- int n , m;
- int di[] = {-1, 1, 0, 0, 1};
- int dj[] = { 0, 0,-1, 1, -1};
- int ordine[] = {8,6,7,9,5,4,3,2,1,0};
- vector<array<int,2>> cifre[10] =
- {
- { {RIGHT,4}, {DOWN,6}, {LEFT,4}, {UP,5} }, // 0
- { {LEFT_DOWN,1}, {RIGHT,1}, {DOWN,5} }, // 1
- { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {DOWN,3}, {RIGHT,4}}, // 2
- { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {RIGHT,4}, {DOWN,3}, {LEFT,4} }, // 3
- { {DOWN,3}, {RIGHT,4}, {UP,3}, {DOWN,6} }, // 4
- { {RIGHT,4}, {LEFT,4}, {DOWN,3}, {RIGHT,4}, {DOWN,3}, {LEFT,4} }, // 5
- { {RIGHT,4}, {LEFT,4}, {DOWN,6}, {RIGHT,4}, {UP,3}, {LEFT,3} }, // 6
- { {RIGHT,4}, {DOWN,2}, {LEFT_DOWN,2}, {DOWN,2} }, // 7
- { {RIGHT,4}, {DOWN,6}, {LEFT,4}, {UP,5}, {DOWN,2}, {RIGHT,3} }, // 8
- { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {UP,3}, {RIGHT,4}, {DOWN,6}, {LEFT, 4} } // 9
- };
- bool tryMove(int &x, int &y, int type, int k)
- {
- for(int i = 1;i<=k;i++)
- {
- int cX = x + di[type] * i;
- int cY = y + dj[type] * i;
- if(cX < 1 || cY < 1 || cX > n || cY > m)
- return false;
- if(mat[cX][cY] == '0') return false;
- }
- x += di[type] * k;
- y += dj[type] * k;
- return true;
- }
- int canvas[10][8];
- void draw(int &x, int &y, int type, int k)
- {
- canvas[x][y] = 1;
- for(int i = 1;i<=k;i++)
- {
- int cX = x + di[type] * i;
- int cY = y + dj[type] * i;
- canvas[cX][cY] = 1;
- }
- x += di[type] * k;
- y += dj[type] * k;
- }
- void afiseaza_cifrele()
- {
- for(int cif = 0;cif<10;cif++)
- {
- for(int it = 1;it<=9;it++)
- for(int it2 = 1;it2<=7;it2++)
- canvas[it][it2] = 0;
- int x = 2, y = 2;
- for(auto it : cifre[cif])
- draw(x,y,it[0],it[1]);
- for(int it = 1;it<=9;it++,cout << '\n')
- {
- if(cif == 1)
- cout << " "; // ca sa arate frumos
- for(int it2 = 1;it2<=7;it2++)
- {
- if(canvas[it][it2] == 1)
- cout << (char)(219) << ' ';
- else cout << ' ' << ' ';
- }
- }
- cout << '\n' << '\n';
- }
- }
- int identif(int x, int y)
- {
- for(int nr = 0;nr<10;nr++)
- {
- int cX = x, cY = y;
- bool valid = true;
- for(auto it : cifre[ordine[nr]])
- if(tryMove(cX,cY,it[0],it[1]) == false) valid = false;
- if(valid) return ordine[nr];
- }
- return -1;
- }
- int cnt, frecv[10];
- int main()
- {
- // afiseaza_cifrele();
- cin >> n >> m;
- for(int i = 1;i<=n;i++)
- for(int j = 1;j<=m;j++)
- cin >> mat[i][j];
- for(int i = 1;i<=n;i++)
- for(int j = 1;j<=m;j++)
- if(mat[i][j] == '1')
- {
- int val = identif(i,j);
- if(val != -1)
- cnt++, frecv[val]++;
- }
- cout << cnt << '\n';
- for(int i = 0;i<10;i++)
- if(frecv[i] > 0)
- cout << i << ' ' << frecv[i] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement