sicily--1818. 成绩转换

  1. 试用STL 的map 容器
  2. 在存储成绩时将名字与“成绩”(转换为ABCDE后)的匹配,查询时直接找到输出

// Problem#: 1818
// Submission#: 1005080
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
    int test_num;
    cin >> test_num;

    for(int i = 0; i < test_num; i++)
    {
        int stu_num, search_num;
        cin >> stu_num >> search_num;
        map<string, string> m;
        
        for(int j = 0; j < stu_num; j++)
        {
            string name;
            cin >> name;
            
            string grade;
            int grade_num;
            cin >> grade_num;
            if(grade_num >= 0 && grade_num <= 59 )
                grade = "E";
            else
                if(grade_num >= 60 && grade_num <= 69)
                    grade = "D";
                else
                    if(grade_num >= 70 && grade_num <= 79)
                        grade = "C";
                    else
                        if(grade_num >= 80 && grade_num <= 89)
                            grade = "B";
                        else
                            if(grade_num >= 90 && grade_num <= 100)
                                grade = "A";
                            else
                                grade = "Score is error!";

            map<string, string>::iterator  it;
            it = m.find(name);
            if(it == m.end())//在容器中还未有该名字的信息
                m.insert(pair<string, string>(name, grade));
            else
                it->second = grade;

        }

        for(int k = 0; k < search_num; k++)
        {
            string name;
            cin >> name;
            map<string, string>::iterator  it;
            it = m.find(name);
            cout << it->second << endl;
        }
    }
    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值