Aramic script

In Aramic language words can only represent objects.html

Words in Aramic have special properties:ios

  • A word is a root if it does not contain the same letter more than once.
  • root and all its permutations represent the same object.
  • The root xx of a word yy is the word that contains all letters that appear in yy in a way that each letter appears once. For example, the rootof "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?c++

Input

The first line contains one integer nn (1n1031≤n≤103) — the number of words in the script.編程

The second line contains nn words s1,s2,,sns1,s2,…,sn — the script itself. The length of each string does not exceed 103103.app

It is guaranteed that all characters of the strings are small latin letters.spa

Output

Output one integer — the number of different objects mentioned in the given ancient Aramic script.xml

Examples
input
Copy
5
a aa aaa ab abb
output
Copy
2
input
Copy
3
amer arem mrea
output
Copy
1
Note

In the first test, there are two objects mentioned. The roots that represent them are "a","ab".htm

In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".blog

意思是問有幾個root,root的意思是一個字符串中全部的不重複字母,無關順序。 好比abbbcd的root是abcd。ip

面向STL編程,寫的具蠢,用了一個map標記出現過的字符,而後掃了一遍,最後用set維護。

#include <iostream>
#include <bits/stdc++.h>
#define maxn 300005
using namespace std;

string findroot(string a)
{   int i;string b;
    map<char,bool> mp;
    for(i=0;i<a.size();i++)
    {
        mp[a[i]]=1;
    }
    for(i='a';i<='z';i++)
    {
        if(mp[i])
        {
           b.push_back(i);
        }
    }
    return b;
}
string a[1005];
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int j;
    bool vis[1005]={0};
    set<string> s;
    for(i=1;i<=n;i++)
    {
        s.insert(findroot(a[i]));
    }
        int cnt=s.size();
    cout<<cnt<<endl;
    return 0;
}
相關文章
相關標籤/搜索