044 编程填空:数据库内的学生信息



#include 
#include 
#include 
#include 
#include 
using namespace std;

// 在此处补充你的代码
template>
class MyMultimap:public multimap {
public:
    void Set(T1 name_,T2 score_) {
        typename multimap::iterator lowi = multimap::lower_bound(name_);
        typename multimap::iterator upi = multimap::upper_bound(name_);
        for (;lowi != upi;++lowi) {
            lowi->second = score_;
        }

    }
    

};

template
ostream& operator << (ostream& os, const pair& pp) {
    os << "(" << pp.first << "," << pp.second << ")";
    return os;
}

struct Student
{
    string name;
    int score;
};
template 
void Print(T first, T last) {
    for (;first != last; ++first)
        cout << *first << ",";
    cout << endl;
}
int main()
{

    Student s[] = { {"Tom",80},{"Jack",70},
                    {"Jone",90},{"Tom",70},{"Alice",100} };

    MyMultimap mp;
    for (int i = 0; i < 5; ++i)
        mp.insert(make_pair(s[i].name, s[i].score));
    Print(mp.begin(), mp.end()); //按姓名从大到小输出

    mp.Set("Tom", 78); //把所有名为"Tom"的学生的成绩都设置为78
    Print(mp.begin(), mp.end());



    MyMultimap > mp2;
    for (int i = 0; i < 5; ++i)
        mp2.insert(make_pair(s[i].score, s[i].name));

    Print(mp2.begin(), mp2.end()); //按成绩从小到大输出
    mp2.Set(70, "Error");          //把所有成绩为70的学生,名字都改为"Error"
    Print(mp2.begin(), mp2.end());
    cout << "******" << endl;

    mp.clear();

    string name;
    string cmd;
    int score;
    while (cin >> cmd) {
        if (cmd == "A") {
            cin >> name >> score;
            if (mp.find(name) != mp.end()) {
                cout << "erroe" << endl;
            }
            mp.insert(make_pair(name, score));
        }
        else if (cmd == "Q") {
            cin >> name;
            MyMultimap::iterator p = mp.find(name);
            if (p != mp.end()) {
                cout << p->second << endl;
            }
            else {
                cout << "Not Found" << endl;
            }
        }
    }
    return 0;
}