题解 | #统计单词#

统计单词

https://www.nowcoder.com/practice/11c6e7c9987c4ab48f8cdd8834c27064

#include <iostream>
using namespace std;

int main(){
	string str;
	while (getline(cin,str)){
		int i,count,j=0;	//count是单词长度
		for (i = 0; str[i] !='.';i+=(count+1)){
			count = 0;//重置
			for (j = i;str[j] !=' ' && str[j] !='.';j++){
				count++;
			}
			cout <<count <<" ";
			if (str[j] == '.') break;
		}
	}
}

全部评论

相关推荐

投递华为等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务