挖掘机技术哪家强(20)

来源:互联网 发布:java decision tree 编辑:程序博客网 时间:2024/04/27 07:15
#include<cstdlib>#include<cstdio>#include<map>#include<iostream>/************************************************************************** Map的特点: 1、存储Key-value对* 2、支持快速查找,查找的复杂度基本是Log(N)* 3、快速插入,快速删除,快速修改记*/************************************************************************/using namespace std;map<int, int> m;int main(int argc, char *argv[]){    int n;    cin >> n;    int max = 0;    for (int i = 0; i<n; i++){        int index, score;        cin >> index >> score;        m[index] += score;        if (m[index]>m[max]){//写上这两行代码就不用itereator了            max = index;        }    }    //map<int, int>::iterator it;    //int index;    //int maxscore = -1;    //for (it = m.begin(); it != m.end(); it++){    //  if (it->second>maxscore){    //      index = it->first;    //      maxscore = it->second;    //  }    //}    cout << max <<" "<< m[max] << endl;}
0 0