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]--;
            }
        }
    }
  • 相关阅读:
    DRF内置限流组件之自定义限流机制
    DRF内置权限组件之自定义权限管理类
    DRF内置认证组件之自定义认证系统
    java基础(15)--多态
    java基础(13)--静态变量、静态代码块、实例代码块
    java基础(12)--static变量/方法 与 无 static的变量/方法的区别
    java基础(11)--封装
    java基础(10)--空指针异常
    java基础(9)--方法重载
    java基础(8)--键盘输入
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9152544.html
Copyright © 2011-2022 走看看