View Code of Problem 58

#include<stdio.h>
#include<string.h>
int main(){
	char s[1000];
	gets(s);
	int count=0,flag=0;
	int len=strlen(s);
	int i;
	for(i=0;i<len;i++){
		while(s[i]==' '){
			flag=1;
			i++;
		}
		if(flag==1){
			count++;
			flag=0;
		}
	}
	if(s[len-1]==' ')
	printf("%d\n",count);
	else
		printf("%d\n",count+1);
}

Double click to view unformatted code.


Back to problem 58