- 试用STL 的map 容器
- 在存储成绩时将名字与“成绩”(转换为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;
}