adhassic @ 2023-02-01 13:46:18
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int i, n, num, sum;
int count = 0;
char s[10000], str[200];
scanf("%s", str);
n = strlen(str);
strcat(s, str);
for (i = 2;i <= n;i++)
{
scanf("%s", str);
strcat(s, str);
}
printf("%d ", n);
for (i = 0, sum = 0, num = '0';i <= strlen(s);i++)
{
if (s[i] == num)
{
sum++;
}
else
{
num = s[i];
printf("%d ", sum);
sum = 1;
}
}
return 0;
}
这个代码在我编译器上输入样例后的结果是 7 0 10032 14
by ForgotDream_CHN @ 2023-02-01 13:54:15
是不是要把第二个循环中的 i <= strlen(s)
换成 i < strlen(s)
?
by ForgotDream_CHN @ 2023-02-01 13:54:38
但是好像你的代码在我电脑上跑的结果是正确的
by ForgotDream_CHN @ 2023-02-01 13:55:43
能不能问下您的测试环境?
by caocong @ 2023-02-01 14:06:05
初始化试试看
by adhassic @ 2023-02-01 21:21:52
@ForgotDream_CHN VS2022
by adhassic @ 2023-02-01 21:24:15
@ForgotDream_CHN 我电脑跑出来的还是不对的,我是学题解写的,最后实在找不到错误试着交了一下,居然过了