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 jiangyichen_10 @ 2024-11-02 14:57:18

@xiaoli2013

那它只要AC了就是正确代码


by xiaoli2013 @ 2024-11-02 14:58:29

@jiangyichen_10 ……我只是好奇测试点怎么过的


by jiangyichen_10 @ 2024-11-05 12:35:22

@xiaoli2013

[i==n]是一个下标,如果i==n,下标就是是'true'反之为'false'


by hzyhnbw @ 2024-11-10 20:07:05

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int s=0;
    getline(cin,a);
    for(int i=0;i<a.size();i++)
        if(a[i]==' '&&s!=0)
        {
            cout<<s<<",";
            s=0;
        }
        else if(a[i]!=' ')
            s++;
    cout<<s;
    return 0;
}

上一页 |