409 - Excuses, Excuses!
2012-05-30 00:39
162 查看
题目http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350
找下面的句子中上面关键词出现的最多的句子 一样多的话按给的顺序输出
将下面的句子分解成小的只含字母字符串 然后依次与上面查找比较 找出数量最多的就行
View Code
找下面的句子中上面关键词出现的最多的句子 一样多的话按给的顺序输出
将下面的句子分解成小的只含字母字符串 然后依次与上面查找比较 找出数量最多的就行
View Code
#include <stdio.h> #include<string.h> struct node { char c[25]; int flag; }; int strcm(char a[],char b[]) { int k, i,flag = 1; if(strlen(a) == strlen(b)) { for(i = 0 ; i < strlen(a) ; i++) if(a[i]!=b[i]&&(a[i]-b[i] != 32)&&(b[i]-a[i]!=32)) { flag = 0; break; } if(flag == 0) k = 0; else k = 1; } else k = 0; return k; } int main() { int i, j, k, n, m,count[100],g,x,max,lag,y = 0; struct node a[25]; char str[100][72],b[72]; while(scanf("%d%d%*c", &n,&m)!=EOF) { y++; memset(count, 0, sizeof(count)); for(i = 0 ; i < n; i++) { gets(a[i].c); } for(i = 1 ; i <= m ; i++) { gets(str[i]); for(x = 0 ; x < n ; x++) a[x].flag = 1; k = strlen(str[i]); g = 0; j = 0; while(j<k) { lag = 0; while((str[i][j]>='a'&&str[i][j]<='z')||(str[i][j]>='A'&&str[i][j]<='Z')) { b[g] = str[i][j]; j++; g++; lag = 1; } j++; if(lag == 1) { b[g] = '\0'; for(x = 0 ; x < n ; x++) { if(a[x].flag!=0&&strcm(a[x].c,b) ==1) { count[i]++; a[x].flag = 0; break; } } g = 0; } } } max = count[1]; for(i = 1 ; i <= m ; i++) { if(max<count[i]) max = count[i]; } printf("Excuse Set #%d\n", y); for(i = 1; i <= m ; i++) if(count[i] == max) puts(str[i]); puts(""); } return 0; }
相关文章推荐
- 409 Excuses, Excuses!
- UVA 409 Excuses, Excuses!
- uva 409 Excuses, Excuses!(字符串处理)
- 409 - Excuses, Excuses!
- Excuses, Excuses! UVa409 字符串
- UVA 409 Excuses, Excuses!
- uva 409 Excuses, Excuses!
- UVa_409 - Excuses, Excuses!
- UVa409_Excuses, Excuses!(小白书字符串专题)
- UVAOJ 409 ——Excuses, Excuses! 模拟
- UVA 409 Excuses(借口)
- 409 - Excuses, Excuses!
- UVa 409 Excuses! Excuses!
- UVa 409 - Excuses, Excuses!
- UVa 409 Excuses, Excuses! (字符串匹配)
- Excuses, Excuses! - UVa 409 哈希字符串
- UVA - 409 Excuses, Excuses!
- UVA - 409 Excuses, Excuses!
- UVA - 409 Excuses, Excuses!
- uva--409-- Excuses, Excuses!