题解 | 统计单词
#include<iostream> using namespace std; /* *统计单词 * */ int main(){ string s1; while(cin>>s1){ int n = s1.length(); int count = 0; bool flag = false; for(int i = 0;i<n;i++){ if(s1[i]!='.'){ count++; }else{ flag = true; } } if(flag){ cout<<count<<endl; }else{ cout<<count<<" "; } } }