题目描述(洛谷上的cf题CF975A Aramic script)
In Aramic language words can only represent objects.
Words in Aramic have special properties:
A word is a root if it does not contain the same letter more than once.
A root and all its permutations represent the same object.
The root x x of a word y y is the word that contains all letters that appear in y y in a way that each letter appears once. For example, the root of “aaaa”, “aa”, “aaa” is “a”, the root of “aabb”, “bab”, “baabb”, “ab” is “ab”.
Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
输入输出格式
输入格式:
The first line contains one integer n n ( 1 \leq n \leq 10^3 1≤n≤10
3
) — the number of words in the script.
The second line contains n n words s_1, s_2, \ldots, s_n s
1
,s
2
,…,s
n
— the script itself. The length of each string does not exceed 10^3 10
3
.
It is guaranteed that all characters of the strings are small latin letters.
输出格式:
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
#include<iostream>
#include<set>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
char a[1000];
int main()
{
set<string>ss; //注意是string不是char,一个是串一个是个
int n,i,sum=0,len;
cin>>n;
for(i=0;i<n;i++)
{
scanf("%s",a);
sort(a,a+strlen(a));
len=unique(a,a+strlen(a))-a;
a[len]='\0'; //unique只是把重复的字母丢到后面去了所以加一个结束符号使得后面重复的被去掉
ss.insert(a); //一个一个插入ss中,利用set的不重复性可以轻易的得到根的数目
}
cout<<ss.size()<<endl;
return 0;
}