Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- char map[51][51];
- char change[51][51];
- int dx[4]={1,-1,0,0};
- int dy[4]={0,0,1,-1};
- int cnt=0;
- void swap(char& a, char& b)
- {
- char temp=a;
- a=b;
- b=temp;
- }
- int main()
- {
- cin>>n;
- for(int i=0; i<n; i++)
- {
- for(int k=0; k<n; k++)
- {
- cin>>map[i][k];
- }
- }
- for(int i=0; i<n; i++)
- {
- for(int k=0; k<n; k++)
- {
- for(int j=0; j<4; j++)
- {
- int curi=i+dx[j];
- int curk=k+dy[j];
- int sum=0;
- if(curi>=0 && curi<n && curk>=0 && curk<n)
- {
- bool check=true;
- swap(map[i][k], map[curi][curk]);
- char na=map[i][k];
- for(int s=i-1; s>=0; s--)
- {
- if(na==map[s][k])
- sum++;
- else
- break;
- }
- for(int s=i+1; s<n; s++)
- {
- if(na==map[s][k])
- sum++;
- else
- break;
- }
- if(sum>cnt)
- cnt=sum;
- sum=0;
- for(int s=k-1; s>=0; s--)
- {
- if(na==map[i][s])
- sum++;
- else
- break;
- }
- for(int s=k+1; s<n; s++)
- {
- if(na==map[i][s])
- sum++;
- else
- break;
- }
- if(sum>cnt)
- cnt=sum;
- swap(map[i][k], map[curi][curk]);
- }
- }
- }
- }
- cout<<cnt+1<<endl;
- }
Add Comment
Please, Sign In to add comment