View Code of Problem 58

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str;
    getline(cin,str);
    int flag = 0;
    int count = 0;
    for(int i = 0; i < str.size(); i ++){
        if(str[i] == ' ')
            flag = 0;
        else if(flag == 0){
            count ++;
            flag = 1;
        }
    }
    cout << count <<endl;
    return 0;
}

Double click to view unformatted code.


Back to problem 58