ttkuilei @ 2022-07-27 14:28:30
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
char a[40010]={'0'};
int i=1,sum=0;
while(cin>>a[i]) i++;
cout<<sqrt(i);
for(int j=1;j<i;j++) {
if(a[j]==a[j-1]) sum++;
else {
cout<<sum<<" ";
sum=1;
}
}
cout<<sum;
return 0;
}
是while(cin>>a[i])
那里输入没停吗??
[疑惑]
by ttkuilei @ 2022-07-27 14:57:48
@DogSeven
输出结果:7.48331 3 1 3 1 3 1 3 1 3 4 1 3 1 3 1 3 1 3 1 3 1 3 1 7 1
就离谱
7.48331^2=56
后面一堆加起来也是56
by qczrz6v4nhp6u @ 2022-07-27 15:01:56
@tangjiayang az 我改了改你的代码都AC了呀
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
char a[40010]={'0'};
int i=1,sum=0;
while(cin>>a[i])i++;
i--;
cout<<sqrt(i);
for(int j=1;j<=i;j++) {
if(a[j]==a[j-1]) sum++;
else {
cout<<" "<<sum;
sum=1;
}
}
cout<<" "<<sum;
return 0;
}
by qczrz6v4nhp6u @ 2022-07-27 15:02:57
@tangjiayang 你多读了换行符
by ttkuilei @ 2022-07-27 15:08:17
@DogSeven 好像是
应该是scanf("%c",&a[i])!=EOF
的问题
改成cin>>a[i]
就好了
by _Cppsteve_ @ 2022-07-27 15:45:00
@tangjiayang 用洛谷在线IDE就可以避免这种问题