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

      

  • 相关阅读:
    MySQL存储树形数据优化技笔记
    收集18个高大上的浏览器小技巧
    收集18个高大上的浏览器小技巧
    盘点15个不起眼但非常强大的 Vim 命令
    盘点15个不起眼但非常强大的 Vim 命令
    为什么开发者应该摒弃敏捷?(转)
    为什么开发者应该摒弃敏捷?(转)
    MySQL 中事务、事务隔离级别详解
    pandas数据对齐
    Bokeh绘图
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/8982059.html
Copyright © 2011-2022 走看看