Advertisement
Hezov

Pbinfo EasyOCR

Jul 2nd, 2025
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <array>
  4. using namespace std;
  5. ifstream cin("easyocr.in");
  6. ofstream cout("easyocr.out");
  7. #define UP 0
  8. #define DOWN 1
  9. #define LEFT 2
  10. #define RIGHT 3
  11. #define LEFT_DOWN 4
  12. char mat[1001][1001];
  13. int n , m;
  14. int di[] = {-1, 1, 0, 0, 1};
  15. int dj[] = { 0, 0,-1, 1, -1};
  16. int ordine[] = {8,6,7,9,5,4,3,2,1,0};
  17. vector<array<int,2>> cifre[10] =
  18. {
  19.     { {RIGHT,4}, {DOWN,6}, {LEFT,4}, {UP,5} }, // 0
  20.     { {LEFT_DOWN,1}, {RIGHT,1}, {DOWN,5} }, // 1
  21.     { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {DOWN,3}, {RIGHT,4}}, // 2
  22.     { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {RIGHT,4}, {DOWN,3}, {LEFT,4} }, // 3
  23.     { {DOWN,3}, {RIGHT,4}, {UP,3}, {DOWN,6} }, // 4
  24.     { {RIGHT,4}, {LEFT,4}, {DOWN,3}, {RIGHT,4}, {DOWN,3}, {LEFT,4} }, // 5
  25.     { {RIGHT,4}, {LEFT,4}, {DOWN,6}, {RIGHT,4}, {UP,3}, {LEFT,3} }, // 6
  26.     { {RIGHT,4}, {DOWN,2}, {LEFT_DOWN,2}, {DOWN,2} }, // 7
  27.     { {RIGHT,4}, {DOWN,6}, {LEFT,4}, {UP,5}, {DOWN,2}, {RIGHT,3} }, // 8
  28.     { {RIGHT,4}, {DOWN,3}, {LEFT,4}, {UP,3}, {RIGHT,4}, {DOWN,6}, {LEFT, 4} } // 9
  29. };
  30. bool tryMove(int &x, int &y, int type, int k)
  31. {
  32.     for(int i = 1;i<=k;i++)
  33.     {
  34.         int cX = x + di[type] * i;
  35.         int cY = y + dj[type] * i;
  36.         if(cX < 1 || cY < 1 || cX > n || cY > m)
  37.             return false;
  38.         if(mat[cX][cY] == '0') return false;
  39.     }
  40.     x += di[type] * k;
  41.     y += dj[type] * k;
  42.     return true;
  43. }
  44. int canvas[10][8];
  45. void draw(int &x, int &y, int type, int k)
  46. {
  47.     canvas[x][y] = 1;
  48.     for(int i = 1;i<=k;i++)
  49.     {
  50.         int cX = x + di[type] * i;
  51.         int cY = y + dj[type] * i;
  52.         canvas[cX][cY] = 1;
  53.     }
  54.     x += di[type] * k;
  55.     y += dj[type] * k;
  56. }
  57. void afiseaza_cifrele()
  58. {
  59.     for(int cif = 0;cif<10;cif++)
  60.     {
  61.         for(int it = 1;it<=9;it++)
  62.             for(int it2 = 1;it2<=7;it2++)
  63.                 canvas[it][it2] = 0;
  64.         int x = 2, y = 2;
  65.         for(auto it : cifre[cif])
  66.             draw(x,y,it[0],it[1]);
  67.         for(int it = 1;it<=9;it++,cout << '\n')
  68.         {
  69.             if(cif == 1)
  70.                 cout << "    "; // ca sa arate frumos
  71.             for(int it2 = 1;it2<=7;it2++)
  72.             {
  73.                 if(canvas[it][it2] == 1)
  74.                     cout << (char)(219) << ' ';
  75.                 else cout << ' ' << ' ';
  76.             }
  77.         }
  78.         cout << '\n' << '\n';
  79.     }
  80. }
  81. int identif(int x, int y)
  82. {
  83.     for(int nr = 0;nr<10;nr++)
  84.     {
  85.         int cX = x, cY = y;
  86.         bool valid = true;
  87.         for(auto it : cifre[ordine[nr]])
  88.             if(tryMove(cX,cY,it[0],it[1]) == false) valid = false;
  89.         if(valid) return ordine[nr];
  90.     }
  91.     return -1;
  92. }
  93. int cnt, frecv[10];
  94. int main()
  95. {
  96.     // afiseaza_cifrele();
  97.     cin >> n >> m;
  98.     for(int i = 1;i<=n;i++)
  99.         for(int j = 1;j<=m;j++)
  100.             cin >> mat[i][j];
  101.     for(int i = 1;i<=n;i++)
  102.         for(int j = 1;j<=m;j++)
  103.             if(mat[i][j] == '1')
  104.             {
  105.                 int val = identif(i,j);
  106.                 if(val != -1)
  107.                     cnt++, frecv[val]++;
  108.             }
  109.     cout << cnt << '\n';
  110.     for(int i = 0;i<10;i++)
  111.         if(frecv[i] > 0)
  112.             cout << i << ' ' << frecv[i] << ' ';
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement