View Code of Problem 58

#include <stdio.h>
#include <string.h>
using namespace std;
int main(){
	char s[1000];
	gets(s);
	int flag = 0;
	int cnt = 0; 
	for( int i=0; i<strlen(s); i++ ){
		if( s[i] == ' '){
			if( flag != 0 ){
				cnt ++;
				flag = 0;
			}
		}else{
				flag = 1;
			}
	}
	printf("%d", cnt );
	return 0;
	
}

Double click to view unformatted code.


Back to problem 58