标签:
题意:给出若干数字 如果能被6整除 输出 BEER!! 否则输出 BOOM!!
思路:用三维数组存下0到9
暴力出每个数的值
求出结果
(这题有点坑在于 1 数字可能不存在 2 数字的数量不确定)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; char num[10][10][10]= { {"***","* *","* *","* *","***"}, {" *"," *"," *"," *"," *"}, {"***"," *","***","* ","***"}, {"***"," *","***"," *","***"}, {"* *","* *","***"," *"," *"}, {"***","* ","***"," *","***"}, {"***","* ","***","* *","***"}, {"***"," *"," *"," *"," *"}, {"***","* *","***","* *","***"}, {"***","* *","***"," *","***"} }; char mat[100][100]; int main() { int i,j,k; int l,m,n; int sum,res; memset(mat,0,sizeof(mat)); while(gets(mat[0])) { sum=0;res=1; for(i=1;i<=4;i++) { gets(mat[i]); } int len=strlen(mat[0]); for(i=0;i<len;i+=4) { for(j=0;j<10;j++) { /*if(j==6) { for(k=0;k<5;k++) { for(l=0;l<3;l++) { printf("%c",num[j][k][l]); } printf("\n"); } }*/ for(k=0;k<5;k++) { for(l=0;l<3;l++) { if(num[j][k][l]==‘*‘) { if(mat[k][l+i]!=num[j][k][l]) { break;} } else if(num[j][k][l]==‘ ‘) { if(mat[k][l+i]==‘*‘) break; } } if(l!=3) { break;} } //if(j==6) printf("%d....\n",k); if(k==5) { break; } } //printf("%d...\n",j); if(j<10) { sum=sum*10+j; } else { res=0; break; } } //printf("%d %d\n",res,sum); if(res==0||sum%6!=0) printf("BOOM!!\n"); else printf("BEER!!\n"); memset(mat,0,sizeof(mat)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4385352.html