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]--;
            }
        }
    }
  • 相关阅读:
    poj 3468 A Simple Problem with Integers 线段树区间更新
    poj 2096 概率dp
    JSP页面的基本结构 及声明变量
    怎样制作一个横版格斗过关游戏 Cocos2d-x 2.0.4
    块状元素与内联元素的差别
    ZOJ 3526 Weekend Party
    linux下javadoc生成文件出现中文乱码
    Centos6.0 通过devtoolset-2工具安装gcc 4.8
    fre7 offonline for firefox
    Aix Lamp openssh bash
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9152544.html
Copyright © 2011-2022 走看看