zzuliOJ 2536: 绿绿学姐与AI 1

题目网址:http://acm.zzuli.edu.cn/problem.php?id=2536

1、题目

2536: 绿绿学姐与AI 1

时间限制: 2 Sec  内存限制: 128 MB
提交: 176  解决: 34
[状态] [讨论版] [提交] [命题人:zzuliacm]

题目描述

绿绿学姐对机器学习很感兴趣,她开始研究机器学习算法。
她研究的第一个问题是语义识别,当她花了十分钟完全掌握之后,发现她手上没有训练样本,于是她把这个任务交给了你,如果你出色地完成了她的任务,就可以吸收她的欧气。
绿绿学姐给你的任务是这样的:
她会给你n个词语,其中前a个是正面的词语,剩下的b个是负面的词语,随后给出Q个句子,你需要输出这个句子偏向负面还是正面。
假设一个句子包含x个正面的词语,y个负面的词语,如果x>y,我们就说这个句子偏向正面,如果x<y,我们就说这个句子偏向负面,如果x==y,我们就说这个句子是中性的。

输入

一个数T,表示数据的组数,1<=T<=50。
每组数据第一行包含三个整数n,a,b,含义如上所述,1<=n<=5000, 1<=a,b<=n,保证a+b==n,。
随后是n行,每行一个词语。
随后一个整数Q,表示Q个句子,1<=Q<=500。
随后Q行,每行一个句子,句子长度不超过1000。
词语长度不超过20,并且只包含小写字母,句子由若干个用一个空格隔开的词语构成。

输出

对于每一个句子输出一行。
如果句子是偏正面的,输出"positive"。
如果句子是偏负面的,输出"negative"。
如果句子是中性的,输出"neuter"。(输出均不包含引号)

样例输入 Copy

1
5 2 3
happy
glad
sad
sorry
cry
3
you are happy
you are sad
you are student

样例输出 Copy

positive
negative
neuter

来源/分类

 2017湖南工业大学校赛

2、C++题解代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

map<string, int> words;

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n, a, b;
        string str;
        scanf("%d%d%d", &n, &a, &b);
        for (int i = 1; i <= n; i++)
        {
            cin >> str;
            words.insert(make_pair(str, i));
        }
        int Q;
        scanf("%d", &Q);
        while (Q--)
        {
            int ans = 0;
            while (cin >> str)
            {
                map<string, int>::iterator it;
                it = words.find(str);
                if (it != words.end())
                {
                    if (it->second <= a)
                        ans++;
                    else
                        ans--;
                }
                if (getchar() == '\n')
                    break;
            }
            if (ans > 0)
                puts("positive");
            else if (ans < 0)
                puts("negative");
            else
                puts("neuter");
        }
        words.clear();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44949135/article/details/108785508