题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805277163896832

又是一道水题,知道使用哈希表以后就很简单了,题目中的队员编号没有使用到,思路与算法笔记基本一致

代码

  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. int main(){
  6. int n;
  7. int tempID,tempStu, tempScore;
  8. vector<int> hashtable(1000);
  9. scanf("%d",&n);
  10. for(int i = 0; i < n; i++){
  11. scanf("%d-%d %d",&tempID, &tempStu, &tempScore);
  12. hashtable[tempID] += tempScore;
  13. }
  14. int maxi = 0;
  15. for(int i = 0; i < 1000; i++){
  16. if(hashtable[i]>hashtable[maxi])maxi = i;
  17. }
  18. printf("%d %d",maxi,hashtable[maxi]);
  19. }