阿波的愛心
此題類似棒球九宮格。
輸入說明:
輸入九宮格投中的資料,以1代表投中的格子,0代表沒投中的格子。
輸出說明:
在螢幕中輸出有幾條連在一起,包刮斜線。
範例輸入:
101
101
101
------------------------我是分格線 並不輸入
101
111
101
範例輸出:
2
5
/**********************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
main()
{
int a,b,c,time,flag1,flag2,temp;
char x[3][3],y[3];
while(1)
{
time=2;flag1=0;flag2=0;temp=0;
for(a=0;a<3;a++)
{
gets(y);
for(b=0;b<3;b++)
{
x[time][b]=y[b];
}
time--;
}
for(a=0;a<3;a++)
{ flag1=0;flag2=0;
for(b=0;b<3;b++)
{
if(x[a][b]==49)
flag1++;
if(x[b][a]==49)
flag2++;
}
if(flag1==3)
{temp++;}
if(flag2==3)
{temp++;}
}
if(x[0][0]=='1'&&x[1][1]=='1'&&x[2][2]=='1')
temp++;
if(x[2][0]=='1'&&x[1][1]=='1'&&x[0][2]=='1')
temp++;
printf("%d\n",temp);
}
return 0;
}
上一篇:後序運算式
下一篇:小光的煩惱[兩個油瓶]