链接:https://vjudge.net/problem/CodeForces-975A
题目
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 of a word y is the word that contains all letters that
appear in 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?
题意
在神奇的Aramic语言中,每个单词都有自己的词根,你的任务就是算出给出的单词一共有几个词根。
例如“aabb”,去掉重复的字母之后就是“ab”,那么“ab”就是它的词根。
对于“aabb”和“bbaa”来说,它们的词根都是“ab”,只不过是顺序问题。
思路
这题思路很清晰:把输入的单词存起来,然后把每个单词的词根全部求出来放到一起,看一下有几个不同的词根就ok。
那么就涉及到除同操作,这个就可以放心交给set了。
看代码,伊丽莎白!
代码
#include <iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=1500;
int main()
{
int n;
string ss[maxn];
set<string>s;
set<char>x;
cin>>n;
for(int i=0; i<n; i++)
cin>>ss[i];
for(int i=0; i<n; i++)
{
x.clear();
string s1="";
for(int j=0; j<ss[i].size(); j++) //求每个单词的词根
x.insert(ss[i][j]);
set<char>::iterator it;
for(it=x.begin();it!=x.end();it++)
s1+=(*it);
s.insert(s1);
}
cout<<s.size()<<endl;
}
《可能是最近作孽有点多导致鼻子长了个痘真的是折磨》