Advertisement
tepyotin2

Untitled

Jul 8th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool isDiag = false;
  5. int N, M ;
  6. vector<string> dat;
  7.  
  8. // SW, S, SE, E, NE, N, NW, W
  9. int dr[] = {-1, -1, -1, 0, 1, 1, 1, 0};
  10. int dc[] = {-1, 0, 1, 1, 1, 0, -1, -1};
  11.  
  12. char get(int r, int c){
  13.     if (r < 0 || r >= N || c < 0 || c >= M)
  14.     {
  15.         return '_';
  16.     }
  17.     return dat[r][c];
  18. }
  19. int main(){
  20.     //isDiag = true;
  21.     freopen(  "moocrypt.in", "r", stdin);
  22.    
  23.    
  24.     int ans = 0;   
  25.    
  26.     if(isDiag) cout << "#1" << endl;
  27.     cin >> N  >> M;
  28.     dat.resize(N); //prepare vector for cin
  29.     for (int i = 0; i < N; i++)
  30.     {
  31.         cin >> dat[i] ; //one array since each line consider as string
  32.     }
  33.    
  34.     if(isDiag) cout << "#2" << endl;
  35.     for (char mch = 'A'; mch <= 'Z'; mch++)
  36.     {
  37.         if (mch == 'M')
  38.         {
  39.             continue;
  40.         }
  41.         if(isDiag) cout << "#2: " << mch << endl;
  42.         //int result = 0;  !!!Problem place invalid place cause invalid result
  43.         for (char och = 'A'; och <= 'Z'; och++)
  44.         {
  45.             if (och == 'O' || och == mch)
  46.             {
  47.                 continue;
  48.             }
  49.             int result = 0; // !!!Fix Problem
  50.             // scan every cell
  51.             for (int i = 0; i < N; i++)
  52.             {
  53.                 for (int j = 0; j < M; j++)
  54.                 {
  55.                     if (get(i, j) != mch)
  56.                     {
  57.                         continue;
  58.                     }
  59.                     for (int k = 0; k < 8; k++)
  60.                     {
  61.                         if (get(i+(1*dr[k]), j+(1*dc[k])) == och
  62.                             && get(i+(2*dr[k]), j+(2*dc[k])) == och
  63.                         )
  64.                         {
  65.                             result++;
  66.                         }
  67.                     }
  68.                    
  69.                 }
  70.             }
  71.             ans = max(ans, result);
  72.         }
  73.     }
  74.    
  75.    
  76.    
  77.    
  78.     if(!isDiag) freopen("moocrypt.out", "w", stdout);
  79.     cout << ans << endl;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement