Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<cmath>
- using namespace std;
- bool debug = false;
- int main()
- {
- int r,c;
- int countall = 0;
- scanf("%d %d",&r,&c);
- char field[r+1][c+1];
- bool visited[r+1][c+1];for(int i=0;i<=r;i++)for(int j=0;j<=c;j++)visited[i][j] = false;
- for(int i=1;i<=r;i++){
- for(int j=1;j<=c;j++){
- scanf(" %c",&field[i][j]);
- if(field[i][j] == 'x')countall++;
- }
- }
- int ca = 0;
- for(int i=1;i<=r;i++){
- for(int j=1;j<= c;j++){
- if(field[i][j] == 'x'){
- int ncI = i;
- int ncJ = j;
- while(field[ncI+1][ncJ+1] == 'x' && ncI+1 <= r && ncJ+1 <= c){
- int ti = i,tj = j;
- ncI++;
- ncJ++;
- while(field[ncI][tj] == 'x' && tj < ncJ)tj++;
- while(field[ti][ncJ] == 'x' && ti < ncI)ti++;
- if(tj != ncJ || ti != ncI){
- ncI--;
- ncJ--;
- break;
- }
- }
- if(debug)printf("Test (%d,%d) -> (%d,%d) = ",i,j,ncI,ncJ);
- int countsquare = 0;
- for(int ti = i ; ti <= ncI ; ti++){
- for(int tj = j ; tj <= ncJ ; tj++){
- if(!visited[ti][tj] && field[ti][tj] == 'x'){
- countsquare++;
- visited[ti][tj] = true;
- countall--;
- }
- }
- }
- if(debug)printf("sq : %d , ca : %d\n",countsquare,countall);
- int size = (int)sqrt((ncI - i + 1)*(ncJ - j + 1));
- if(countsquare == size*size){
- printf("%d %d %d\n",i,j,size);
- ca++;
- if(ca == 2)return 0;
- }
- else if(countall == 0){
- printf("%d %d %d\n",i,j,size);
- return 0;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment