1 .XX...XX.....XX...XX. X..X....X......X.X..X X..X....X.X....X.X..X ......XX.....XX...XX. X..X.X....X....X.X..X X..X.X.........X.X..X .XX...XX.....XX...XX.
02:38
题意:输入7 X 21的字符串,输出时间
分析:直接模拟啊,0-20列,第4 9 10 11 16 列都不是有效的列,剩下的16列表示4个数,并且都是连续的,每一个7 X 4都判断一次,看看是什么数,输出即可
AC代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; char a[10][25]; char ch[7][4]; int fun(char c[7][4])//利用数形状的差距直接判断 { for(int i=0;i<7;i++) for(int j=0;j<4;j++) { if(c[3][1]=='X' && c[3][2]=='X') { if(c[0][1]=='.' && c[0][2]=='.') return 4; if(c[4][0]=='X' && c[5][0]=='X') { if(c[1][0]=='.' && c[2][0]=='.') return 2; if(c[1][3]=='X' && c[2][3]=='X') return 8; return 6; } else { if(c[1][3]=='.' && c[2][3]=='.') return 5; if(c[1][0]=='.' && c[2][0]=='.') return 3; return 9; } } else if(c[3][1]=='.' && c[3][2]=='.') { if(c[1][0]=='X' && c[2][0]=='X') return 0; if(c[0][1]=='X' && c[0][2]=='X') return 7; return 1; } } return -1; } int main() { int t; cin>>t; getchar(); while(t--) { for(int i=0;i<7;i++) scanf("%s",a[i]); int num=0; int coun=0; for(int j=0;j<21;j++) { if(j==4 || j==9 || j==10 || j==11 || j==16) { continue; } else { num++; } if(num%4==0)//累计四行做一次判断 { for(int i=0;i<7;i++) { for(int k=j-3,s=0;k<=j;k++,s++) { ch[i][s]=a[i][k]; } } cout<<fun(ch); coun++; if(coun==2) cout<<":"; } } cout<<endl; } return 0; }
因篇幅问题不能全部显示,请点此查看更多更全内容