Sicily 1818. 成绩转换

来源:互联网 发布:淘宝买中药靠谱么 编辑:程序博客网 时间:2024/05/16 04:32

用了STL的map.

只需要正常输入, 可以达到覆盖效果.

时间有点慢, 用了1.56sec

// Problem#: 1818// Author#: Reid Chan#include <iostream>#include <map>#include <string>using namespace std;void level(int s) {    if (90 <= s && s <= 100) {        cout << 'A' << endl;    } else if (80 <= s && s <= 89) {        cout << 'B' << endl;    } else if (70 <= s && s <= 79) {        cout << 'C' << endl;    } else if (60 <= s && s <= 69) {        cout << 'D' << endl;    } else if (0 <= s && s <= 59){        cout << 'E' << endl;    } else {        cout << "Score is error!" << endl;    }}int main() {    int t;    cin >> t;    while (t--) {        int n, m;        cin >> n >> m;        map<string, int> ppl;        string name;        int score;        for (int i = 0; i < n; ++i) {            cin >> name >> score;            ppl[name] = score;        }        map<string, int>::iterator it;        for (int i = 0; i < m; ++i) {            cin >> name;            it = ppl.find(name);            if (it != ppl.end()) {                level(it->second);            }        }    }    return 0;}                                 


0 0
原创粉丝点击