# 希望大佬们指导一下！我知道我程序后面模拟部分有问题，但我不知道该怎么去改？

#include <stdio.h> int main() { int a, b = 1, i, j, aa[7][7], c[7]; scanf("%d\n", &a); while (a > 0) { for (j = 1; j <= 2; j++) { scanf("%s", c); aa[j][3] = c[0] - '0'; aa[j][4] = c[1] - '0'; aa[j][5] = c[2] - '0'; } for (j = 3; j <= 5; j++) { scanf("%s", c); aa[j][1] = c[0] - '0'; aa[j][2] = c[1] - '0'; aa[j][3] = c[2] - '0'; aa[j][4] = c[3] - '0'; aa[j][5] = c[4] - '0'; aa[j][6] = c[5] - '0'; aa[j][7] = c[6] - '0'; } for (j = 6; j <= 7; j++) { scanf("%s", c); aa[j][3] = c[0] - '0'; aa[j][4] = c[1] - '0'; aa[j][5] = c[2] - '0'; } for (i = 3; i <= 5; i++) { for (j = 1; j <= 2; j++) { if (aa[i][j] == 1) { if (aa[i][j + 1] == 1 && aa[i][j + 2] == 0) b = 0; if (aa[i + 1][j] == 1 && (aa[i + 2][j] == 0 || aa[i - 1][j] == 0)) b = 0; } } for (j = 6; j <= 7; j++) { if (aa[i][j] == 1) { if (aa[i][j + 1] == 1 && aa[i][j + 2] == 0) b = 0; if (aa[i + 1][j] == 1 && (aa[i + 2][j] == 0 || aa[i - 1][j] == 0)) b = 0; } } } for (i = 1; i <= 7; i++) { for (j = 3; j <= 5; j++) { if (aa[i][j] == 1) { if (aa[i][j + 1] == 1 && (aa[i][j + 2] == 0 || aa[i][j - 1] == 0)) b = 0; if (aa[i + 1][j] == 1 && (aa[i + 2][j] == 0 || aa[i - 1][j] == 0)) b = 0; } } } a--; if (b == 0) printf("no\n"); else printf("yes\n"); } }
...全文
218 点赞 收藏 5

5 条回复

https://bbs.csdn.net/topics/380157851
``````#include <stdio.h>
int main() {
int y,x,n,flag;
static char data[9][9];
scanf("%d\n", &n);
while (n > 0) {
scanf("%s%s"  ,data[1]+3,data[2]+3          );
scanf("%s%s%s",data[3]+1,data[4]+1,data[5]+1);
scanf("%s%s"  ,data[6]+3,data[7]+3          );
flag=0;
for(y=1; y<8; y++) {
for(x=1; x<8; x++) {
if(data[y  ][x  ]!='1') continue; //当前位置没棋子则跳过
if(data[y-1][x  ]=='1'&&data[y+1][x  ]=='0'    //垂直方向：110
||data[y-1][x  ]=='0'&&data[y+1][x  ]=='1'    //垂直方向：011
||data[y  ][x-1]=='1'&&data[y  ][x+1]=='0'    //水平方向：110
||data[y  ][x-1]=='0'&&data[y  ][x+1]=='1') { //水平方向：011
flag=1; //出现以上4种情况表示有解
break;
}
}
if(flag==1) break;
}
n--;
if (flag == 1) printf("no\n");
else           printf("yes\n");
}
return 0;
}

``````

``````
#include <stdio.h>
int main() {
int i,j,n,flag;
char data[9][9]= {'\0'};
scanf("%d\n", &n);
while (n > 0) {
scanf("%s%s",data[1]+3,data[2]+3);
scanf("%s%s%s",data[3]+1,data[4]+1,data[5]+1);
scanf("%s%s",data[6]+3,data[7]+3);
flag=0;
for(i=1; i<8; i++) {
for(j=1; j<8; j++) {
if(data[i][j]!='1') continue; //当前位置没棋子则跳过
if(data[i-1][j]=='1'&&data[i+1][j]=='0' //垂直方向：110
||data[i-1][j]=='0'&&data[i+1][j]=='1' //垂直方向：011
||data[i][j-1]=='1'&&data[i][j+1]=='0' //水平方向：110
||data[i][j-1]=='0'&&data[i][j+1]=='1') { //水平方向：011
flag=1; //出现以上4种情况表示有解
break;
}
}
if(flag==1) break;
}
n--;
if (flag == 1) printf("no\n");
else printf("yes\n");
}
return 0;
}
``````

coo135 03-31

``````
#include <stdio.h>
int main() {
int i,j,n,flag;
char data[9][9]= {'\0'};
scanf("%d\n", &n);
while (n > 0) {
scanf("%s%s",data[1]+3,data[2]+3);
scanf("%s%s%s",data[3]+1,data[4]+1,data[5]+1);
scanf("%s%s",data[6]+3,data[7]+3);
flag=0;
for(i=1; i<8; i++) {
for(j=1; j<8; j++) {
if(data[i][j]!='1') continue; //当前位置没棋子则跳过
if(data[i-1][j]=='1'&&data[i+1][j]=='0' //垂直方向：110
||data[i-1][j]=='0'&&data[i+1][j]=='1' //垂直方向：011
||data[i][j-1]=='1'&&data[i][j+1]=='0' //水平方向：110
||data[i][j-1]=='0'&&data[i][j+1]=='1') { //水平方向：011
flag=1; //出现以上4种情况表示有解
break;
}
}
if(flag==1) break;
}
n--;
if (flag == 1) printf("no\n");
else printf("yes\n");
}
return 0;
}
``````

3843

C/C++ 其它技术问题

2021-03-31 03:19