View Code of Problem 58

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{
    char str[1000];
    scanf("%[^\n]",str);
    int num = 0;
    for(int i =0;i<strlen(str);i++)
    {
        if(str[i] == ' '&&str[i+1] != ' ')
            num++;
    }
    if(str[0] != ' ')
    {   
        if(num == 1)
            printf("1\n");
        else
        {
            printf("%d\n",num+1);
        }
    }  
    else
    {
        printf("%d\n",num);
    }
    
    return 0;
}

Double click to view unformatted code.


Back to problem 58