Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isDiag = false;
- int N, M ;
- vector<string> dat;
- // SW, S, SE, E, NE, N, NW, W
- int dr[] = {-1, -1, -1, 0, 1, 1, 1, 0};
- int dc[] = {-1, 0, 1, 1, 1, 0, -1, -1};
- char get(int r, int c){
- if (r < 0 || r >= N || c < 0 || c >= M)
- {
- return '_';
- }
- return dat[r][c];
- }
- int main(){
- //isDiag = true;
- freopen( "moocrypt.in", "r", stdin);
- int ans = 0;
- if(isDiag) cout << "#1" << endl;
- cin >> N >> M;
- dat.resize(N); //prepare vector for cin
- for (int i = 0; i < N; i++)
- {
- cin >> dat[i] ; //one array since each line consider as string
- }
- if(isDiag) cout << "#2" << endl;
- for (char mch = 'A'; mch <= 'Z'; mch++)
- {
- if (mch == 'M')
- {
- continue;
- }
- if(isDiag) cout << "#2: " << mch << endl;
- //int result = 0; !!!Problem place invalid place cause invalid result
- for (char och = 'A'; och <= 'Z'; och++)
- {
- if (och == 'O' || och == mch)
- {
- continue;
- }
- int result = 0; // !!!Fix Problem
- // scan every cell
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < M; j++)
- {
- if (get(i, j) != mch)
- {
- continue;
- }
- for (int k = 0; k < 8; k++)
- {
- if (get(i+(1*dr[k]), j+(1*dc[k])) == och
- && get(i+(2*dr[k]), j+(2*dc[k])) == och
- )
- {
- result++;
- }
- }
- }
- }
- ans = max(ans, result);
- }
- }
- if(!isDiag) freopen("moocrypt.out", "w", stdout);
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement