Sicily 1818. 成绩转换

Time Limit: 5 secs, Memory Limit: 32 MB

Description

保存学生姓名和成绩,然后通过姓名查询该学生的成绩等级。

输入为百分制的成绩,将其转换成对应的等级,具体转换规则如下:

90~100 为 A;
80~89 为 B;
70~79 为 C;
60~69 为 D;
0~59 为 E;

Input

输入有多组数据。第一行为数据组数T。

对于每组数据,第一行包含两个整数 n(1< n<=15000)和 m(1< m<=10000),n 表示学生个数,m 表示查询次数。接下来 n 行,每行包含一名学生的姓名和成绩。再接下来 m 行,每行一个字符串,表示学生姓名。

注意: 数据有可能有重复名字的学生,以最后一次出现的成绩为准。

Output

对于每个查询,输出一行, 表示该学生成绩等级。如果输入数据不在 0~100 范围内,请输出一行:“Score is error!”。


^_^ 五秒的时间给的很慷慨,使用STL中的map可以比较轻松的完成本题。**map在一对一数据元素进行匹配时具有的优势是其他结构所不具备的。**get?

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        map<string, int> score;         // 使用map申明Score结构

        int NumOfInput, NumOfOutput;    
        cin >> NumOfInput
            >> NumOfOutput;

        int num;
        string str;
        while (NumOfInput--)            // 添加学生成绩
        {
            cin >> str >> num;
            score[str] = num;
        }
        while (NumOfOutput--)           // 输出
        {
            cin >> str;
            if (score[str] >= 0)
            {
                if (score[str] <= 59)
                    cout << "E" << endl;
                else if (score[str] <= 69)
                    cout << "D" << endl;
                else if (score[str] <= 79)
                    cout << "C" << endl;
                else if (score[str] <= 89)
                    cout << "B" << endl;
                else if (score[str] <= 100)
                    cout << "A" << endl;
                else
                    cout << "Score is error!" << endl;
            }
            else
                cout << "Score is error!" << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值