UVa 409 - Excuses, Excuses!
2014-06-13 01:19
375 查看
题目:有一些关键词,还有一些说明理由的句子。输出关键词出现最多次数的句子,若有多个都输出。
分析:字符串。把句子拆成单词,依次和所有关键词比较即可。
处理时注意,必须是关键词匹配,不能使前缀。
说明:同以关键词多次出现,按多次计算;每组结束都有换行。
分析:字符串。把句子拆成单词,依次和所有关键词比较即可。
处理时注意,必须是关键词匹配,不能使前缀。
说明:同以关键词多次出现,按多次计算;每组结束都有换行。
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; char keywords[24][24]; char excuses[24][80]; int counts[24]; int small( char a ) { if ( a >= 'A' && a <= 'Z' ) return a +'a'-'A'; else return a; } int find_word( char *a, char *b ) { char buf[80]; int count = 0,move = 0; while ( a[move] ) { while ( a[move] && (small(a[move]) < 'a' || small(a[move]) > 'z') ) move ++; int save = 0; while ( small(a[move]) >= 'a' && small(a[move]) <= 'z' ) buf[save ++] = small(a[move ++]); buf[save] = 0; count += !strcmp(b,buf); } return count; } int main() { int n,m,T = 1; while ( ~scanf("%d%d",&n,&m) ) { //getchar(); for ( int i = 0 ; i < n ; ++ i ) { scanf("%s",keywords[i]); getchar(); } for ( int i = 0 ; i < m ; ++ i ) { gets(excuses[i]); counts[i] = 0; } int max = 0; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) counts[i] += find_word( excuses[i], keywords[j] ); if ( max < counts[i] ) max = counts[i]; } printf("Excuse Set #%d\n",T ++); for ( int i = 0 ; i < m ; ++ i ) if ( counts[i] == max ) printf("%s\n",excuses[i]); printf("\n"); } return 0; }
相关文章推荐
- UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)
- UVA 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(借口)
- uva 409 Excuses, Excuses!
- UVa_409 - Excuses, Excuses!
- UVA409 Excuses, Excuses!解题报告
- UVA - 409 - Excuses, Excuses
- UVa-409-Excuses, Excuses!
- UVa409_Excuses, Excuses!(小白书字符串专题)
- UVa 409 - Excuses, Excuses!
- UVA 409 - Excuses, Excuses!(字符串)
- uva 409 Excuses, Excuses!(字符串模拟)
- uva 409 - Excuses, Excuses!
- Uva 409-Excuses, Excuses!(串)
- UVa 409 Excuses, Excuses!