View Code of Problem 58

#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		s=" "+s;
		int word=0;
		while(true){
			int it=s.find(' ');
			//cout<<it<<endl;
			if(it==s.npos){
				break;
			}
			else{
				if(s[it+1]!=' '&&s[it+1]!='\0'){
					word++;
					//cout<<s[it+1]<<endl;
				}
			}
			s.erase(it,1);
		}
		cout<<word<<endl;
	}
}

Double click to view unformatted code.


Back to problem 58