什么是我的代码中的错误 [英] Whats the mistake in my code
问题描述
All submissions for this problem are available.Recently the company Life Ltd created a new logo for themselves. You are asked to test the design of the logo.
The logo is a 3 * 3 square grid with 9 cells. Each cell contains some lower case english letter. This logo will be considered good if there exist three cells in the shape of an L that contain the letter 'l' (lower case 'L') in each of them. That is, there should be a cell with 'l', its cell directly beneath it should also have 'l' and the cell to the right of the second cell should also have 'l'.
Your task is to tell whether the logo is good or not.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of the test cases follows.
Each of the next three lines contains a description of the logo, i-th of the line contains three characters which denote the i-th row of the logo
输出
对于每个测试用例,根据问题的答案输出是或否。
约束
1≤T≤100
示例输入
3
laz
lla
aaa
ala
lla
aaa
lll
lll
lll
示例输出
是
否
是
我尝试过:
#include< stdio.h>
int main()
{
char logo [3] [3];
int row,col,t,i;
scanf(%d \ n,& t);
for(i = 0; i< t; i ++)
{
for(row = 0; row< 3; row ++)
{
for(col = 0; col< 3; col ++)
{
scanf(%c\ n,& lo go [row] [col]);
}
}
if(logo [0] [ 0] =='l'&& logo [1] [0] =='l'&& logo [1] [1] =='l')
printf( yes \ n);
else if(logo [0] [1] =='l'&& logo [1] [1] =='l'&& ; logo [1] [2] =='l')
printf(yes \ n);
else if(logo [1] [0] =='l'&& logo [2] [0] =='l'&& logo [2] [1] =='l')
printf(是的\ n);
else if(logo [1] [1] =='l'&& logo [2] [1] =='l'&& logo [2] [2] =='l')
printf(yes \ n);
else
printf( no \\\
);
}
}
Output
For each test case, output yes or no according to the answer to the problem.
Constraints
1≤T≤100
Example Input
3
laz
lla
aaa
ala
lla
aaa
lll
lll
lll
Example Output
yes
no
yes
What I have tried:
#include<stdio.h>
int main()
{
char logo[3][3];
int row,col,t,i;
scanf("%d\n",&t);
for(i=0;i<t;i++)
{
for(row=0;row<3;row++)
{
for(col=0;col<3;col++)
{
scanf("%c\n",&logo[row][col]);
}
}
if(logo[0][0]=='l'&&logo[1][0]=='l'&&logo[1][1]=='l')
printf("yes\n");
else if(logo[0][1]=='l'&&logo[1][1]=='l'&&logo[1][2]=='l')
printf("yes\n");
else if(logo[1][0]=='l'&&logo[2][0]=='l'&&logo[2][1]=='l')
printf("yes\n");
else if(logo[1][1]=='l'&&logo[2][1]=='l'&&logo[2][2]=='l')
printf("yes\n");
else
printf("no\n");
}
}
推荐答案
代码中没有错误。如果你愿意,你可以按如下方式重写它。
There is no mistake in your code. You might rewrite it as follows, if you like.
#include<stdio.h>
#define N 3
int is_good(char l[N][N]);
int main()
{
char logo[N][N];
int row,col,t,i;
scanf("%d\n",&t);
for(i=0;i<t;i++)
{
for(row=0;row<3;row++)
{
for(col=0;col<3;col++)
{
scanf("%c\n",&logo[row][col]);
}
}
if ( is_good(logo) )
printf("yes\n");
else
printf("no\n");
}
}
int is_good(char l[N][N])
{
int r,c;
for (r=0; r<N-1; ++r)
for (c=0; c<N-1; ++c)
if ( l[r][c]=='l' && l[r+1][c]=='l' && l[r+1][c+1]=='l')
return 1;
return 0;
}
首先你已经标记了这个问题C#,当它显然是C.
关于你的问题,你正确识别第1组和第3组中的L形状。
Firstly you have tagged this question C# when it is clearly C.
As to your problem, you are correctly identifying the L shape in sets 1 and 3.
这篇关于什么是我的代码中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!