zoukankan      html  css  js  c++  java
  • 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.
    • 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?

    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.

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

    Output

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

    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".

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

    意思是问有几个root,root的意思是一个字符串中所有的不重复字母,无关顺序。 比如abbbcd的root是abcd。

    面向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;
    }
    

      

  • 相关阅读:
    Ajax一个好用简单框架Ajax.dll_________推荐
    米亚罗、理县、都江堰和青城山的灾前照片
    PlatForm在国家卫星气象中心
    CN Grid 项目
    IDL与matlab比较【转】
    家乡宁国
    ISPRS感受
    .NET 连接 Oracle
    编程实现Google Earth和ArcGIS的联动[demo]
    IDL 与 外部语言的几种集成方式(一)——connector
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/8982059.html
Copyright © 2011-2022 走看看