标签:
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072
1 #include<stdio.h> 2 #include<string.h> 3 4 char words[1010][50]; 5 char str[1010]; 6 int n; 7 8 void getword(char str[]) 9 { 10 int flag = 0; 11 int cnt = 0; 12 n = 0; 13 int i = 0; 14 char word[50]; 15 int len = strlen(str); 16 str[len+1] = ‘\n‘; 17 str[len] = ‘ ‘; 18 for(; i<=len; i++) 19 { 20 if(flag == 0) 21 { 22 if(str[i] != ‘ ‘) 23 { 24 word[cnt++] = str[i]; 25 flag = 1; 26 } 27 } 28 else 29 { 30 if(str[i] == ‘ ‘) 31 { 32 word[cnt] = ‘\0‘; 33 strcpy(words[n++], word); 34 cnt = 0; 35 flag = 0; 36 } 37 else 38 word[cnt++] = tr[i]; 39 } 40 } 41 } 42 43 int count() 44 { 45 int i, j; 46 int ntr = 0; 47 for(i=0; i<n; i++) 48 { 49 int flag = 1; 50 for(j=i+1; j<n; j++) 51 if(strcmp(words[i], words[j])==0) 52 flag=0; 53 if(flag) 54 ntr++; 55 } 56 return ntr; 57 } 58 59 int main() 60 { 61 while(gets(str) && strcmp(str, "#")) 62 { 63 getword(str); 64 printf("%d\n", count()); 65 } 66 return 0; 67 }
标签:
原文地址:http://www.cnblogs.com/forerve/p/4339620.html