题解 P1808 【单词分类_NOI导刊2011提高(01)】
当当当当,新方法咯
首先定一个map数组,然后将每个读入的字符串进行内部排序,使小的字符在前,如果没有出现过,组数+1,定义为出现过
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<string,bool>z;//存储字符串是否出现过
string a;
int n,sum;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a;
sort(a.begin(),a.end());//排序
if(!z[a]){//如果没有出现过,组数+1
sum++;
z[a]=1;
}
}
cout<<sum;
return 0;
}