tj
2025-08-25 15:57:29
发布于:云南
3阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <unordered_map>
using namespace std;
int main() {
string input;
getline(cin, input);
istringstream iss(input);
vector<string> names;
unordered_map<string, int> countMap;
vector<string> order;
string name;
while (iss >> name) {
if (name == "0") {
break;
}
names.push_back(name);
}
for (const string& n : names) {
if (countMap.find(n) == countMap.end()) {
order.push_back(n);
countMap[n] = 1;
} else {
countMap[n]++;
}
}
for (const string& n : order) {
cout << n << " " << countMap[n] << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个