我这个程序为什么测试的时候正确,但全WA
查看原帖
我这个程序为什么测试的时候正确,但全WA
1305985
Gordon1楼主2024/4/21 16:21
#include<iostream>
#include<cmath>
using namespace std;
int a[40010];
char b[40010];
int main(void)
{
	int i=1;
	while(cin>>b[i])
	{
		if(b[i]!='0'&&b[i]!='1')
		{
			break;
		}
		a[i]=b[i]-'0';
		++i;
	}
	cout<<sqrt(i-1)<<" ";
	a[i]=2;
	bool c=false;
	int count=0;
	for (int j=1;j<=i; )
	{
		if(a[j]==c)
		{
			count+=1;
			++j;
		}
		else if(a[j]==!c)
		{
			cout<<count<<" ";
			count=0;
			c=!c;
		}
		else
		{
			cout<<count<<" ";
			return 0; 
		}
	}
}

请大家给我讲解一下

2024/4/21 16:21
加载中...