#题目大意
测试样例
样例输入
2
3
red
red
blue
5
a
b
e
d
e
样例输出
red 2
blue 1
a 1
b 1
e 2
d 1
#总体思路
可以用map存储气球的颜色和数量,至于气球的顺序可以另开一个队列存储。
#include <iostream>
using namespace std;
#include <map>
#include <queue>
int main()
{
int t;
cin >> t;
string col;
存储颜色和数量
map<string, int>mp;
存储气球的顺序
queue<string> q;
while (t--)
{
mp.clear();
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> col;
这个气球第一次出现
if (!mp.count(col))
q.push(col);
mp[col]++;气球是否第一次出现,都要进行这个操作
}
while(!q.empty())
{
string t = q.front();
cout << t << ' ' << mp[t] << "\n";
q.pop();
}
}
return 0;
}