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]--;
            }
        }
    }
  • 相关阅读:
    RHEL双网卡绑定
    图解机房收费系统报表制作的全过程
    linux内存管理机制
    hdu4432 Sum of divisors(数论)
    树和而叉查找树的实现
    49. 面向对象的LotusScript(十五)之Log4Dom下
    HDU 4009 不定根最小树形图
    模拟+二分 poj-1019-Number Sequence
    SQL Server 事务日志传输
    百度开放云java+tomcat部署web项目-小皇帝詹姆斯
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9152544.html
Copyright © 2011-2022 走看看