zoukankan      html  css  js  c++  java
  • Dubious Document

    问题 K: Dubious Document

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 34  解决: 28
    [提交][状态][讨论版][命题人:admin]

    题目描述

    Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
    He will receive a headline which contains one of the strings S1,…,Sn tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.
    Find the longest string that can be created regardless of which string among S1,…,Sn the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.

    Constraints
    1≤n≤50
    1≤|Si|≤50 for every i=1,…,n.
    Si consists of lowercase English letters (a - z) for every i=1,…,n.

    输入

    Input is given from Standard Input in the following format:
    n
    S1

    Sn

    输出

    Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.

    样例输入

    3
    cbaa
    daacc
    acacac
    

    样例输出

    aac
    

    提示

    The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth. Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    int main()
    {
        int n;
        char str[55];
        cin>>n;
        cin>>str;
        int len = strlen(str);
        int ans[50]={0};
        for(int i=0;i<len;i++)
        {
            ans[str[i]-'a']++;
        }
        for(int i=0;i<n-1;i++)
        {
            cin>>str;
            len = strlen(str);
            int temp[55]={0};
            for(int j=0;j<len;j++)
            {
                temp[str[j]-'a']++;
            }
            for(int i=0;i<26;i++)
            {
                ans[i] = min(ans[i],temp[i]);
            }
        }
        for(int i=0;i<26;i++)
        {
            while(ans[i])
            {
                printf("%c",i+'a');
                ans[i]--;
            }
        }
    }
  • 相关阅读:
    Linux下启用异步IO
    ORA-20011 ORA-29913 KUP-11024
    OCP 11G 053题库解析汇总链接(601-712)
    OCP 11G 053题库解析汇总链接(201-400)
    OCP 11G 053题库解析汇总链接(401-600)
    OCP 11G 053题库解析汇总链接(1-200)
    OCP 11G 052题库解析汇总链接
    OCP 11G 051题库解析汇总链接
    Vue外部js引入做为全局变量
    Java实现atoi函数
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9152544.html
Copyright © 2011-2022 走看看