View Code of Problem 58

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
	string s;
	getline(cin, s);
	int flag = 1;
	int sum = 0;
	for (char c : s) {
		if (c == ' '&&flag == 1) {
			sum++;
			flag = 0;
		}
		if (c != ' ') {
			flag = 1;
		}
	}
	cout << sum;
}

Double click to view unformatted code.


Back to problem 58