View Code of Problem 58

#include<iostream>
#include<string> 
using namespace std;
int main(){
	string str;
	getline(cin,str);
	int len=str.length(),sum=0,i=0;
	while(str[i]==' ')	i++;
	for(;i<len;i++){
		while(str[i]!=' ')	i++;
		sum++;
		while(str[i]==' ')	i++;
	}
	printf("%d",sum);
	return 0;
}

Double click to view unformatted code.


Back to problem 58