-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword_count.c
More file actions
32 lines (31 loc) · 876 Bytes
/
Copy pathword_count.c
File metadata and controls
32 lines (31 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* =========================================================
* Filename: word_count.c
* Description: source http://uva.onlinejudge.org/external/4/494.html
* 在C programming language 中的单词记数问题
*
* =========================================================
*/
#include <stdio.h>
#include <stdbool.h>
#define IsLetter(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'z'))
int main(){
int c;
int count = 0;
bool InWord = false;
while((c = getchar()) != EOF){
if(c == '\n'){
printf("%d\n",count);
count = 0; //reset count
}
else{
if(!IsLetter(c))
InWord = false;
else if (!InWord){ //same with if(IsLetter(c) && !InWord)
++count;
InWord = true;
}
}
}
return 0;
}