uva409 Excuses, Excuses!(字符串处理)

版权声明:博主表示授权一切转载啦,不过要写上原作者哦:) https://blog.csdn.net/qq_15714857/article/details/44873973

1.关键词在句子中出现必须是单词的形式,关键词是ab的时候在句子中出现的合法形式应该是:ab c 或ab,c等,abc则不算在内。



*Author : Flint_x 
*Created Time : 2015-04-04 15:36:49 
*File name : uva409.cpp 

using namespace std;
const double eps(1e-8);
typedef long long lint;
string key[25];
string ex[25];
string ex2[25];
int k,e;
int find(int m){  
    int i, j, flag = 0;  
    for (j = 1; j <= k; j++)  
        if (ex[m].find(key[j]) != string::npos) {  
            int a = ex[m].find(key[j]);  
            if (ex[m][a - 1] < 97 || ex[m][a - 1] > 122) {  
                int length = key[j].size();  
                if (ex[m][a + length] < 97 || ex[m][a + length] > 122)  
//  cout << flag;  
    return flag;  
int main(){

    int cnt = 0 ;
    while(cin >> k >> e){
        cnt ++;
        int count[25];
        int count2[25];
        for(int i = 1 ; i <= k ; i++){
            cin >> key[i];
//      getline(cin,ex[1]);
        for(int i = 1 ; i <= e ; i++){
//          char x = getchar();
//          cout << x << endl;
            ex2[i] = ex[i];
//          cout << ex[i] << endl;
            for(int j = 0 ; j < ex[i].length() ; j++){
                if(ex[i][j] >= 'A' && ex[i][j] <= 'Z'){
                    ex[i][j] = ex[i][j] + 32;

        for(int j = 1 ; j <= e ; j++){
                count[j] = find(j);
                count2[j] = count[j];
        sort(count + 1, count + 1 + e);
        printf("Excuse Set #%d\n",cnt) ;
        for(int i = 1 ; i <= e ; i++){
            if(count[e] == count2[i]){
//              cout << count[e];
                cout << ex2[i] << endl;
        cout << endl;
    return 0;

Excuses, Excuses!Excuses, Excuses!


Problem DescriptionrnJudge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case. rn rnrnInputrnInput to your program will consist of multiple sets of data. rnrnLine 1 of each set will contain exactly two integers. The first number (1 <= K <= 20) defines the number of keywords to be used in the search. The second number (1 <= E <= 20) defines the number of excuses in the set to be searched.rnrnLines 2 through K+1 each contain exactly one keyword.rnrnLines K+2 through K+1+E each contain exactly one excuse.rnrnAll keywords in the keyword list will contain only contiguous lower case alphabetic characters of length L (1 <= L <= 20) and will occupy columns 1 through L in the input line.rnrnAll excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [SPMamp".,!?&] not including the square brackets and will not exceed 70 characters in length.rnrnExcuses will contain at least 1 non-space character. rnrn rnrnOutputrnFor each input set, you are to print the worst excuse(s) from the list. rnrnThe worst excuse(s) is/are defined as the excuse(s) which contains the largest number of incidences of keywords.rnrnIf a keyword occurs more than once in an excuse, each occurrence is considered a separate incidence.rnrnA keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space. rnrnFor each set of input, you are to print a single line with the number of the set immediately after the string ``Excuse Set #". (See the Sample Output). The following line(s) is/are to contain the worst excuse(s) one per line exactly as read in. If there is more than one worst excuse, you may print them in any order. rnrnAfter each set of output, you should print a blank line. rn rnrnSample Inputrn5 3rndogrnaternhomeworkrncanaryrndiedrnMy dog ate my homework.rnCan you believe my dog died after eating my canary... AND MY HOMEWORK?rnThis excuse is so good that it contain 0 keywords.rn6 5rnsuperhighwayrncrazyrnthermonuclearrnbedroomrnwarrnbuildingrnI am having a superhighway built in my bedroom.rnI am actually crazy.rn1234567890.....,,,,,0987654321?????!!!!!!rnThere was a thermonuclear war!rnI ate my dog, my canary, and my homework ... note outdated keywords?rn rnrnSample OutputrnExcuse Set #1rnCan you believe my dog died after eating my canary... AND MY HOMEWORK?rnrnExcuse Set #2rnI am having a superhighway built in my bedroom.rnThere was a thermonuclear war!


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他