#include<stdio.h> int main() { int i,j,m,n; int a=0,b=0,c=0; char ss[1000][1000]; scanf("%d %d",&m,&n); for(i=0;i<m;i++) scanf("%s",ss); for(i=0;i<m;i++) for(j=0;j<n;j++) { if(ss[i][j]=='R') a++; if(ss[i][j]=='G') b++; if(ss[i][j]=='B') c++; } printf("%d %d %d",a,b,c); return 0; }哪里错了
时间: 2023-12-08 16:05:43 浏览: 32
你的代码有两个问题:
1. 在读入队员信息时,应该使用 `scanf("%s", ss[i])` 而不是 `scanf("%s", ss)`,因为 `ss` 是一个二维数组,需要指定具体的行数和列数。
2. 在统计队员数时,应该使用 `if ... else if ... else if ...` 的嵌套结构,而不是使用多个 `if` 语句。因为一个队员只可能属于三个队伍中的一个,如果使用多个 `if` 语句会导致重复计数。
下面是修改后的代码:
```c
#include<stdio.h>
int main() {
int i,j,m,n;
int a=0,b=0,c=0;
char ss[1000][1000];
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
scanf("%s",ss[i]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(ss[i][j]=='R')
a++;
else if(ss[i][j]=='G')
b++;
else if(ss[i][j]=='B')
c++;
}
printf("%d %d %d",a,b,c);
return 0;
}
```
相关问题
#include <stdio.h> #include <math.h> int main() { int a
#include <stdio.h> 是一个C语言的头文件,它包含了一些输入输出函数的声明,比如printf和scanf等。而#include <math.h> 是一个数学库的头文件,它包含了一些数学函数的声明,比如sqrt和sin等。
在你给出的代码中,int main() 是程序的入口函数,它表示程序从这里开始执行。在main函数中,定义了一个整型变量a,但是没有给它赋初值。
如果你想要使用printf函数来输出一些信息,可以在main函数中添加代码,比如:
int main()
{
int a = 10;
printf("a的值是:%d\n", a);
return 0;
}
这样就可以输出a的值为10。你可以根据需要修改a的值和输出的格式。
#include <stdio.h> #include <stdlib.h> int main() { int a=3,b=4,c=5; bool n=a||b+c&&b-c; printf(n); return 0; }
这段代码中存在一些问题。首先,bool类型应该使用"%d"来输出,而不是使用"%f"。其次,逻辑运算符优先级需要注意,应该先计算"b+c"和"b-c"的值,再进行或运算。最后,输出语句应该使用"%d"来输出n的值,而不是使用n本身。修改后的代码如下:
```
#include <stdio.h>
#include <stdlib.h>
int main() {
int a=3,b=4,c=5;
bool n = a || (b+c) && (b-c);
printf("%d", n);
return 0;
}
```
输出结果为1,表示n的值为真(true)。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)