模拟题 找出不能拼凑的最小数

A. An interesting game
Zhouzhou and Dazhongfeng are playing an interesting game. They have
some cards with numbers on them, and all the numbers are between zero and
nine. They can use these cards to make up different numbers. Now they want
to know the smallest number they cannot make up. Can you tell them?

The first line contains an integer T(T 100). The next T lines, each line
contains a string S(
jSj ≤ 100000), the string represents all the cards they have,
each character represents an card.

Output the smallest number they cannot makeup.

3
01234567
2301
1111222

8 4 0


#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int aa[11];
int main()
{
    int num,j;
    string s;
    cin>>num;
    while(num--)
    {
        memset(aa,0,sizeof(aa));
        cin>>s;
        for(int i=0;i<s.length();i++)
        {
            aa[s[i]-'0']++;
        }
        int min=9999999,flag=0;
        for(int i=0;i<10;i++)
        {
            if(aa[i]==0)
            {
                printf("%d\n",i);
                flag=1;
                break;
            }
            if(min>aa[i])
            {
                min=aa[i];
                j=i;
            }
        }
        if(!flag)
        {
            if(j!=0){
           for(int i=0;i<min+1;i++)
           {
               cout<<j;
           }
           cout<<endl;
            }
            else
            {
                cout<<1;
                for(int i=0;i<min+1;i++)
                {
                    cout<<0;
                }
                cout<<endl;
            }
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值