In Aramic language words can only represent objects.html
Words in Aramic have special properties:ios
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?c++
The first line contains one integer nn (1≤n≤1031≤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 one integer — the number of different objects mentioned in the given ancient Aramic script.xml
5
a aa aaa ab abb
2
3
amer arem mrea
1
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; }