题目地址
解题思路
对每一个给出的字符串,进行排序,然后使用map记录出现的次数。这里我用的unordered_map,不知道map能不能过。
AC代码
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main()
{
int t;
unordered_map<string, int> m;
cin >> t;
while (t--)
{
string s;
cin >> s;
sort(s.begin(), s.end());
int num = m[s]++;
cout << num << endl;
}
return 0;
}