小白书训练-Excuses, Excuses!m

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350

题意:没读懂题让人WA到死啊啊啊!大体的意思很简单,就是给你n个单词,m个句子,问包含最多单词的句子是什么,要注意的是,找的是单词,不是字符串,说白了,就是被空格和标点符号明确分开的字符片段,不能直接上find><!!!需要对整个句子划分,然后对比查找。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

struct ANS
{
    int num;
    int no;
} ans[100];

int cmp(ANS a,ANS b)
{
    if(a.num == b.num)
        return a.no < b.no;
    return a.num > b.num;
}

int main()
{
    int n,m;

    string word[100];
    string se[100],xse[100];
    int NO = 1;
    while(cin >> n >> m)
    {
        cin.get();
        memset(ans,0,sizeof(ans));
        for(int i = 0; i < n; i++)
        {
            cin >> word[i];
            cin.get();
            for(string::iterator p = word[i].begin(); p < word[i].end(); p++)
                *p = tolower(*p);
        }

        for(int i = 0; i < m; i++)
        {
            getline(cin,se[i]);
            xse[i] = se[i];
            for(string::iterator p = xse[i].begin(); p < xse[i].end(); p++)
            {
                if(isalpha(*p))
                    *p = tolower(*p);
                else
                    *p = ' ';
            }
        }

        for(int i = 0; i < m; i++)
        {
            ans[i].no = i;
            int s = 0,e = 0;
            for(string::iterator p = xse[i].begin(); p < xse[i].end(); p++,e++)
            {
                string tmp;
                while(*p != ' ' && p < xse[i].end())
                {
                    tmp += *p;
                    p++;
                }
                for(int j = 0; j < n; j++)
                {
                    //cout << word[j] << '-' << tmp << endl;
                    if(word[j] == tmp)
                        ans[i].num++;
                }

            }

        }

        sort(ans,ans + m,cmp);
        int imax = ans[0].num;

        cout << "Excuse Set #" << NO++ << endl;
        for(int i = 0; i < m; i++)
            if(ans[i].num == imax)
                cout << se[ans[i].no] << endl;

        cout << endl;
    }
    return 0;
}

梦续代码:http://www.hypo.xyz

时间: 2024-08-23 08:06:58

小白书训练-Excuses, Excuses!m的相关文章

小白书训练-Where&#39;s Waldorf?

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951 题意:给了一个字母表,然后给了若干单词,问这些单词的首地址在字母表的什么地方. 因为可以八个顺序查找,比较麻烦,但不难,之前就做个,这次在做,改进就是用数组+循环控制八个方向,而不是写了好多各个方向的代码. 代码: #include<iostream> #inclu

小白书训练-Andy&#39;s First Dictionary

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756 题意:给你一段文字,把所有的单词挑出来,然后排序打印. 首先是挑出来,用指针加数组轻轻松解决问题,然后排序,因为用数组不能快拍,便用了string,先转换为string然后一个快拍. 打印的时候不能打印重复的,因此,在打印的时候一个判断就好. 因为数组大小问题RE到死啊啊啊啊

小白书训练-Palindromes

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题意镜像和回文串判断 代码: #include <iostream> #include <cstring> using namespace std; int main() { char s[30]; while(cin >> s) { //p

小白书训练-Automatic Editing

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1056 题意:替换单词,这个题不难,但写题解想想就是泪啊TAT,最大要注意的地方就是要替换彻底,就是替换完之后如果可以替换接着替换,其次,一定要一个单词一个单词的替换. 剩下的看代码吧: #include <iostream> #include <stdio.h&g

小白书训练-Automatic Poetry

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1302 题意:就是用<和>吧一句话截断为5部分,然后先打印s1s2s3s4s5,然后再输入一句话,然后在打印这句话(去除'.'),然后打印s4s3s2s5.其实就是个模拟,没有难度,就是英语有点问题,用指针分分钟的事情. 代码: #include <iostream

小白书训练-Artificial Intelligence?

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=478 题意:实在是太挫了,这个题目做了好久.TAT,题意很简单,就是用语言描述了电压U电流I功率P中的任意两个,求另一个. 字符串转化以及单位判断嘛,不难,一直在WA,只是因为头文件用的是cstdio,用了stdio.h就恢复正常了,真是的,简直了!!!! 代码: #include

小白书训练-Decode the tape

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1819 题意:纸带打孔来保持二进制数,打孔便是1,否者为0.这个带子用ASCII保存了一个字符串,一个模拟.用数组使劲RE和WA,无语了.还是一个一个读入过掉的. 代码: #include <iostream> #include <cstdio> using

UVa409_Excuses, Excuses!(小白书字符串专题)

解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include <iostream> using namespace std; int k,e,num[100],cnt; struct node { int v; node *next[26]; }; node *newnode() { node *p=new node; p->v=0; int i; for(i

UVa10115_Automatic Editing csdn(小白书字符串专题)

解题报告 题意: 替换字符串,一个单词可重复替换 思路: 这种题都很恶心. #include <iostream> #include <cstring> #include <cstdio> #include <map> using namespace std; char str[1000][1000],ch[1000][1000],sh[1000],str1[1000]; int main() { int n,i,j; while(~scanf("