View Code of Problem 58

#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    getline(cin,s);
    int result = 0;
    int i = 0;
    while (i < s.length()) {
        if (s[i] == ' ' && i > 0 && s[i - 1] != ' '){
                result++;
        }
        i++;
    }
    cout << result;
}

Double click to view unformatted code.


Back to problem 58