题目链接: 字符串分类
1. 先将每个字符串排序, 用 sort() 即可. 这样即使字母位置不同的字符串在排序后都一样.
2. 将排序后的字符串保存在 set 中, set 能确保相同的字符串只会保存一次.
3. set 的大小就是题解.
题解代码:
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;int main()
{int n;cin >> n;set<string> s;string str;for(int i = 0; i < n; ++i){cin >> str;sort(str.begin(), str.end());s.insert(str);}cout << s.size() << endl;return 0;
}