是这个意思不
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/318373173196175.png?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<string, int> commentMap;
unordered_map<string, int> likeMap;
int currentId = 1;
int maxLikes = 0;
int maxId = -1;
for (int i = 0; i < n; i++) {
string comment;
int likes;
cin >> comment >> likes;
// 如果这是一条原创评论
if (commentMap.find(comment) == commentMap.end()) {
commentMap[comment] = currentId;
likeMap[comment] = likes;
currentId++;
// 更新点赞数最多的评论
if (likes > maxLikes) {
maxLikes = likes;
maxId = commentMap[comment];
}
else if (likes == maxLikes && commentMap[comment] < maxId) {
maxId = commentMap[comment];
}
}
// 如果这是一条重复的评论,但点赞数更高
else if (likes > likeMap[comment]) {
likeMap[comment] = likes;
// 如果此时的点赞数更高,则更新最大值
if (likes > maxLikes) {
maxLikes = likes;
maxId = commentMap[comment];
}
else if (likes == maxLikes && commentMap[comment] < maxId) {
maxId = commentMap[comment];
}
}
}
cout << maxId << endl;
return 0;
}