怪文書 / Dubious Document

原题地址
借助大佬的分析:
题意 :用n个字符串S1…Sn 。每个字符串都由小写的a…z中的字母组成。找出每个字符串共有的字符并挑选最少的。如:样例: S1 :cbaa
S2 :daacc
S3 :acacac
三个字符串共有的字符是 a 和 c ,其中
S1 :有2个a S2 :有2个a S3 :有3个a 挑选最少的 – aa
S1 : 有1个c S2 :有2个c S3 : 有3个c 挑选最少的 – c
最后把挑选出来的字符按字典序最小排列 – aac
解题思路:就直接扫一遍,每次就取最少的就行了(主要是考对字符串的处理)
暂时模仿出来一个代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
//#include <string.h>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*struct shi
{
    int x;
    int T;
} s[100000];
int cmp(shi a,shi b)
{
    return a.x<b.x;
}
long long cmd(long long a, long long  b)
{
    return a > b;
}*/
int dp[1000000],hh[1000000];
int mox[]= {1,0};
int moy[]= {0,1};
int sx,sy;
int ex,ey;
int n,r;
int falg,step=INF;
/*void dfs(int a, int b,int sum){
    sum+=dp[a][b];
    if(a<=n)
        dfs(a+1,b,sum);
    if(b<=r)
        dfs(a,b+1,sum);
    if(a==n&&b==r&&sum>0&&sum<step)
        step = sum;
}*/
int h[1000000]= {0};
char s[100];
int main()
{
    scanf("%d",&n);
    memset(hh,0x3f,sizeof(hh));
    for(int i=1; i<=n; i++)
    {
        cin >>s;
        memset(dp,0,sizeof(dp));
        //int len = s.length();
        for(int j=strlen(s)-1; j>=0; j--)

            dp[s[j]]++;
           // cout<<s[j];

        for(int j='a'; j<='z'; j++)
            hh[j]=min(hh[j],dp[j]);

    }
    for(int j='a'; j<='z'; j++)
    {
        for(int k=0; k<hh[j]; k++)
            putchar(j);
    }

    return 0;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值