View Code of Problem 58

#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>

using namespace std;


int main()
{
	string str;
	getline(cin, str);

	int res = 0;
	for (int i = 0; i < str.size() - 1; i++) {

		if (isalpha(str[i]) && str[i + 1] == ' ')
			res++;
	}

	if (str[str.size() - 1] != ' ' && str[str.size() - 2] == ' ')
		res++;

	cout << res;
}

Double click to view unformatted code.


Back to problem 58