COJ1174(Shining Gems)
枚举题。第一次WA可能是因为读数据时用了getchar()吸收回车。
View Code
1 #include <stdio.h> 2 #define N 1005 3 char map[N][N]; 4 int n,m; 5 char equal(char a,char b,char c) 6 { 7 return (a==b&&b==c); 8 } 9 char is_combo() 10 { 11 int i,j; 12 for(i=0;i<n;i++) 13 { 14 for(j=0;j+2<m;j++) if(equal(map[i][j],map[i][j+1],map[i][j+2])) return 1; 15 } 16 for(j=0;j<m;j++) 17 { 18 for(i=0;i+2<n;i++) if(equal(map[i][j],map[i+1][j],map[i+2][j])) return 1; 19 } 20 return 0; 21 } 22 char is_over() 23 { 24 int i,j; 25 for(i=0;i<n;i++) 26 { 27 for(j=0;j+1<m;j++) 28 { 29 if(j-2>=0&&equal(map[i][j-2],map[i][j-1],map[i][j+1])) return 0; 30 if(j+3<m&&equal(map[i][j],map[i][j+2],map[i][j+3])) return 0; 31 if(i-1>=0&&i+1<n&&equal(map[i-1][j],map[i][j+1],map[i+1][j])) return 0; 32 if(i-1>=0&&i+1<n&&equal(map[i-1][j+1],map[i][j],map[i+1][j+1])) return 0; 33 if(i-2>=0&&equal(map[i-2][j],map[i-1][j],map[i][j+1])) return 0; 34 if(i+2<n&&equal(map[i][j+1],map[i+1][j],map[i+2][j])) return 0; 35 if(i-2>=0&&equal(map[i-2][j+1],map[i-1][j+1],map[i][j])) return 0; 36 if(i+2<n&&equal(map[i][j],map[i+1][j+1],map[i+2][j+1])) return 0; 37 } 38 } 39 for(j=0;j<m;j++) 40 { 41 for(i=0;i+1<n;i++) 42 { 43 if(i-2>=0&&equal(map[i-2][j],map[i-1][j],map[i+1][j])) return 0; 44 if(i+3<n&&equal(map[i][j],map[i+2][j],map[i+3][j])) return 0; 45 if(j-1>=0&&j+1<m&&equal(map[i][j-1],map[i+1][j],map[i][j+1])) return 0; 46 if(j-1>=0&&j+1<m&&equal(map[i+1][j-1],map[i][j],map[i+1][j+1])) return 0; 47 if(j-2>=0&&equal(map[i][j-2],map[i][j-1],map[i+1][j])) return 0; 48 if(j+2<m&&equal(map[i+1][j],map[i][j+1],map[i][j+2])) return 0; 49 if(j-2>=0&&equal(map[i+1][j-2],map[i+1][j-1],map[i][j])) return 0; 50 if(j+2<m&&equal(map[i][j],map[i+1][j+1],map[i+1][j+2])) return 0; 51 } 52 } 53 return 1; 54 } 55 int main() 56 { 57 int i,j; 58 while(~scanf("%d%d",&n,&m)) 59 { 60 for(i=0;i<n;i++) scanf("%s",map[i]); 61 if(is_combo()) puts("Combo"); 62 else if(is_over()) puts("Game Over"); 63 else puts("Enjoy It"); 64 } 65 return 0; 66 }