UVA - 409 - Excuses, Excuses
2014-04-13 16:07
483 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=350
题意:
输入nKey行关键字,输入nCase行借口,判断哪行借口包含最多关键字。有多个时同时输出。
解题:
在借口字符串中找关键字,并统计好。注:只有连续的单词才能组成关键字,即"abca ca se"中,只包含一次关键字"ca",而不是两次。
为了把单词抽出,把所以非字母字符转变成空格,再用sstream把一个个单独单词分离出来,对比即可。
(开始WA的,后来在厕所想到思路。。。)
题意:
输入nKey行关键字,输入nCase行借口,判断哪行借口包含最多关键字。有多个时同时输出。
解题:
在借口字符串中找关键字,并统计好。注:只有连续的单词才能组成关键字,即"abca ca se"中,只包含一次关键字"ca",而不是两次。
为了把单词抽出,把所以非字母字符转变成空格,再用sstream把一个个单独单词分离出来,对比即可。
(开始WA的,后来在厕所想到思路。。。)
#include <iostream> #include <sstream> #include <string> #include <vector> #include <string.h> #include <stdio.h> using namespace std; const int MAXN = 20; void fun_str(string &str) { for ( int i=0; i<str.length(); i++ ) { if ( isalpha(str[i]) ) { str[i] = tolower(str[i]); } // end if else { str[i] = ' '; } // end else } // end for } int main() { int nKey, nCase; int index = 0; while ( cin >>nKey >>nCase ) { index++; cin.ignore(); vector <string> vKey; vector <string> vExcuses; vector <string> vExcusesEx; string strIn; for ( int i=0; i<nKey; i++ ) { getline(cin, strIn); vKey.push_back(strIn); } // end for for ( int i=0; i<nCase; i++ ) { getline(cin, strIn); vExcuses.push_back(strIn); fun_str(strIn); vExcusesEx.push_back(strIn); } // end for int szCount[MAXN]; memset(szCount, 0, sizeof(szCount)); int max = -1; for ( int i=0; i<nCase; i++ ) { istringstream strStream(vExcusesEx[i]); string strTmp; while ( strStream >>strTmp ) { for ( int j=0; j<nKey; j++ ) { if ( strTmp == vKey[j] ) { szCount[i]++; } // end if } // end for } // end while if ( szCount[i] > max ) { max = szCount[i]; } // end if } // end for cout <<"Excuse Set #" <<index <<'\n'; for ( int i=0; i<nCase; i++ ) { if ( szCount[i] == max ) { cout <<vExcuses[i] <<'\n'; } // end if } // end for cout <<endl; } // end while return 0; }
相关文章推荐
- UVA 题目409 - 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!
- 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, Excuses!
- UVa_409 - Excuses, Excuses!
- Uva 409-Excuses, Excuses!(串)
- HDU 1606(POJ 1598 UVA 409) Excuses, Excuses!(字符串匹配处理)
- UVa409_Excuses, Excuses!(小白书字符串专题)
- UVA 409-Excuses, Excuses!(模拟)
- uva 409 Excuses, Excuses!