0分求助!!!!!!!!

B2120 单词的长度

caoyanyang @ 2024-11-10 17:39:00

#include<iostream>
using namespace std;
int main(){
    string a;
    int cs=0;
    getline(cin,a);
    for(int i=0;i<a.length();i++){
        if(a[i]!=' '&&i!=a.length()-1){
            cs++;
        }else{
            if((a[i]==' '||i!=a.length()-1)&&cs>0){
                cout<<cs<<",";
                cs=0;
            }
        }
    }
    if(cs>0){
        cout<<cs;
    }
    return 0;
} 

by codingwen @ 2024-11-10 17:41:17

hack:

a   a

输出 1,

@caoyanyang


by caoyanyang @ 2024-11-10 17:45:14

@codingwen 谢谢


|