luogu_00 @ 2024-12-07 21:22:49
#include<bits/stdc++.h>
using namespace std;
string words;
int length[300];
int main(){
int i=0;
getline(cin,words);
for(int j=0;j<words.length();j++){
if(words[j]==' '){
if(words[j-1]!=' '){
i++;
}
continue;
}
length[i]++;
}
for(int j=0;j<i;j++){
cout<<length[j];
if(j!=i-1){
cout<<",";
}
}
return 0;
}
为什么这段代码只能得
by iamsh @ 2024-12-07 21:28:49
#include<bits/stdc++.h>
using namespace std;
string words;
int length[300];
int main(){
int i=0;
getline(cin,words);
for(int j=0;j<words.length();j++){
if(words[j]==' '){
if(words[j-1]!=' '){
i++;
}
continue;
}
length[i]++;
}
for(int j=0;j<=i;j++){//共有 i 个单词
cout<<length[j];
if(j!=i){//边界也要改
cout<<",";
}
}
return 0;
}
by luogu_00 @ 2024-12-07 21:31:10
@iamsh 已AC,谢。