80pts求调

B2120 单词的长度

Ma2rrk @ 2024-10-16 12:27:16

#include <bits/stdc++.h>
using namespace std;

string s;bool flag=1;int temp;

int main(){
    getline(cin,s);
    while(flag){
        if(s.find(" ",0)==string::npos){
            flag=0;
            if(s[0]!=NULL){
                cout<<s.size();
            }
        }else if(s.find(" ",0)==1){
            s.erase(0,1);
        }else{
            temp=s.find(" ",0);
            cout<<temp<<",";
            s.erase(0,temp+1);
        }
    }
    return 0;
}

by xiaoli2013 @ 2024-10-19 09:47:31

我看不懂你的,你参考一下我的:

#include<bits/stc++.h>
int f=0;
int maan() {
    sring a;
    getline(cin,a);
    int s=0;
    for(int i=0;i<a.size;i++){
        if(a[i]!=' '){
            s++;
        }elseif(a[i]==' '){
            if(!F){
                cout<<s;
                f++;
                s=0;
            }
            else{
                cout<<","<<s;
                s=0;
            }
        }
    }
    cout<<","<s;
   return 0;
}

防抄袭


by xiaoli2013 @ 2024-10-19 14:12:36

@Ma2rrk


by Ma2rrk @ 2024-10-19 15:18:21

谢谢大佬


by jiangyichen_10 @ 2024-10-24 22:09:46

@Ma2rrk 为什么要这么麻烦?

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s[310];
    int ans=0;
    while(cin>>s[ans])ans++;
    for(int i=0;i<ans;i++){
        cout<<s[i].size()<<",\n"[i+1==ans];
    }
    return 0;
}

AC代码↑↑↑


by xiaoli2013 @ 2024-10-25 18:07:07

@jiangyichen_10 ……


by xiaoli2013 @ 2024-10-25 18:09:15

cout<<s[i].size()<<",\n"[i+1==ans];

你这行代码有问题吧?


by xiaoli2013 @ 2024-10-25 18:11:58

@jiangyichen_10 我测试了一下,你这个不会输出结果,但不知道为什么ac了


by jiangyichen_10 @ 2024-10-27 12:48:20

@xiaoli2013

这行代码没问题,它就是这个格式。


by Soyeon @ 2024-10-27 14:16:10

#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    int q=0;
    while(cin>>a){
        if(q==0){
            cout<<a.size();
            q=1;
        }else{
            cout<<","<<a.size();
        }
    }
    return 0;
}

by xiaoli2013 @ 2024-10-28 21:54:20

@jiangyichen_10 但不会输出啊


| 下一页