AnUpdatingHam @ 2022-12-01 11:12:12
在Visual Studio里,#1自测通过,
但是提交全是WA………………
代码如下:
#include <iostream>
#include<cstdio>
using namespace std;
int A[210][210];
int main()
{
int N=0;
char c=getchar();
while(c!='\n')
{
N++;
if (c == '0')A[1][N] = 2;//将0记录为2
else A[1][N] = 1;
c = getchar();
}
for(int i=2;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
cin>>c;
if (c == '0')A[i][j] = 2;
else A[i][j] = 1;
}
}
int flag = 2;//2代表0
int myNum = 0;
cout << N ;
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(A[i][j]==flag)
{
myNum++;
}
else
{
cout << " " << myNum;
myNum = 1;
flag = A[i][j];
}
}
}
if(myNum!=1)cout << " " << myNum << endl;
return 0;
}
by jason_sun @ 2022-12-01 11:27:26
换行符问题,读字符串试试
by aser12 @ 2022-12-01 13:44:56
不要用getchar 存的样例后面可能还有空格不是单纯的换行
by AnUpdatingHam @ 2022-12-02 23:59:35
AC啦!谢谢大佬!! ORZ
by Dreamer_Boy @ 2022-12-11 11:33:07
附带说一句,测试数据比一定有样例。
@AnUpdatingHam
by Payton123 @ 2023-01-06 00:32:54
遇到了同样的问题,一筹莫展中
by shiranai @ 2023-02-08 19:51:22
把
while(c!='\n')
改成
while(c!='\r')
就可以了
by shiranai @ 2023-02-08 19:53:16
换行要么是\n要么是\r\n
两种都试一试就好了