View Code of Problem 58

#include<iostream>

using namespace std;

int main(){
	string s;
	int count=0;
	getline(cin,s);

	for(int i=0;i<s.length();++i){
		
		if(s[i]!=' ' && s[i+1]==' '){
			count++;
		}
	}
	if(s[s.length()-1]!=' '){
		count++;
	}
	cout<<count;
	return 0;
} 

Double click to view unformatted code.


Back to problem 58