Advertisement
Cosmin3105

asciimat

Feb 22nd, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("asciimat.in");
  8.  
  9. int c, k, x, colmx;
  10. char s[3005], *p;
  11. int mat[3005][3005];
  12.  
  13. int main()
  14. {
  15.     fin >> c;
  16.     fin.get();
  17.     fin.getline(s, 3005);
  18.     fin >> k;
  19.  
  20.     int linie = 1;
  21.     p = strtok(s, " ");
  22.     while(p){
  23.         if(strlen(p) > colmx)
  24.             colmx = strlen(p);
  25.  
  26.         int col = 7;
  27.         for(int i = 0 ; i < strlen(p); i++){
  28.             x = p[i];
  29.             int h = 1;
  30.             while(x){
  31.                 mat[linie][col-h+1] = x%2;
  32.                 h++;
  33.                 x /= 2;
  34.             }
  35.             col += 7;
  36.         }
  37.  
  38.         linie++;
  39.  
  40.         p = strtok(NULL, " ");
  41.     }
  42.     colmx = colmx*7;
  43.  
  44.     int l = 0, nr = 0;
  45.     for(int i =1; i < linie; i++)
  46.         for(int j = 1; j <= colmx; j++){
  47.             if(mat[i][j] == 1)
  48.                 mat[i][j] += min(mat[i-1][j], min(mat[i-1][j-1],mat[i][j-1]));
  49.  
  50.             if(mat[i][j] > l)
  51.                 l = mat[i][j];
  52.  
  53.             if(mat[i][j] >= k)
  54.                 nr++;
  55.  
  56.         }
  57.  
  58.     if(c == 1)
  59.         cout << l;
  60.     else
  61.         cout << nr;
  62.  
  63.  
  64.     // for(int i = 1; i < linie; i++){
  65.    //     for(int j = 1; j <= colmx; j++)
  66.    //         cout << mat[i][j] << " ";
  67.    //     cout << "\n";
  68.    // }
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement