文章

75

粉丝

66

获赞

75

访问

6.7k

头像
统计单词(C++) 题解:
P1394 华中科技大学
发布于2024年4月28日 23:50
阅读数 97

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

string str;

int main()
{
    while(getline(cin, str))
    {
        int cnt = 0;
        for(int i = 0; i < str.size(); i ++)
        {
            if(str[i] != ' ') cnt ++;
            if((str[i - 1] == ' ' && str[i] != ' ') || str[i] == '.')
            {
                cout << cnt - 1 << " ";
                cnt = 1;
            }
        }
    }
    
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发