Find the smallest number that can't be pieced together

A. An interesting gameZhouzhou and Dazhongfeng are playing an interesting game. They havesome cards with numbers on them, and all the numbers are between zero andnine. They can use these cards to make up different numbers. Now they wantto 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 linecontains 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.301234567230111112228 4 0



















#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int aa[11];
intmain()
{
    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;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325744665&siteId=291194637