题解 | #统计单词#
统计单词
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; } } }