View Code of Problem 58

#include<iostream>
#include<string>

using namespace std;

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

Double click to view unformatted code.


Back to problem 58