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]--;
            }
        }
    }
  • 相关阅读:
    创建数据库的那些事
    同步、异步、阻塞、非阻塞我的理解
    Openfire MultiUserChat 多用户聊天 消息发送
    JAVA 随机字符串
    OF 同步异步问题的改进
    Openfire S2S 监听与消息处理
    MySQL FEDERATED 存储引擎
    一个S2S通信中的同步、异步问题的解决
    Openfire Monitoring/jinglenodes plugin error
    Java Cache System JCS(一) 使用方法
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9152544.html
Copyright © 2011-2022 走看看