文章

34

粉丝

0

获赞

6

访问

995

头像
统计单词 题解:
P1394 华中科技大学
发布于2025年8月5日 20:55
阅读数 39

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

int main(){
	
	string s;
	while(getline(cin, s)){
	
		int cnt = 0;
		char before = ' ';
		for(int i = 0; i < s.length(); i ++){
			char ch = s[i];
			if(!isspace(ch)){ // 当前为字母
				// 判断是否为句点
				if(ch != '.') cnt ++;
				else if(cnt != 0) cout << cnt << " "; // 考虑句点与单词有空格的情况
			} else if(!isspace(before) && isspace(ch)){ // 前一个为字母,当前为空格
				cout << cnt << " ";
				cnt = 0;
			}
			before = ch;
		}
		cout << "\n";
	}
		
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发