Birthday Candles
|
All submissions for this problem are available.
The chef is preparing a birthday cake for one of his guests,
and his decided to write the age of the guest in candles on the cake.
There are 10 types of candles, one for each of the digits '0' through '9'.
The chef has forgotten the age of the guest, however, so doesn't know whether he has enough candles of the right types.
For example, if the guest were 101 years old, the chef would need two '1' candles and one '0' candle.
Given the candles the chef has, your task is to determine the smallest positive integer that cannot be represented with those candles.
and his decided to write the age of the guest in candles on the cake.
There are 10 types of candles, one for each of the digits '0' through '9'.
The chef has forgotten the age of the guest, however, so doesn't know whether he has enough candles of the right types.
For example, if the guest were 101 years old, the chef would need two '1' candles and one '0' candle.
Given the candles the chef has, your task is to determine the smallest positive integer that cannot be represented with those candles.
Input:
Input will begin with an integer T≤100, the number of test cases.
Each test case consists of a single line with exactly 10 integers, each between 0 and 8, inclusive.
The first integer of each test case represents the number of '0' candles the chef has,
the second integer represents the number of '1' candles the chef has, and so on.
Each test case consists of a single line with exactly 10 integers, each between 0 and 8, inclusive.
The first integer of each test case represents the number of '0' candles the chef has,
the second integer represents the number of '1' candles the chef has, and so on.
Output:
For each test case, output on a single line the smallest positive integer that cannot be expressed with the given candles.
Sample input:
3 2 1 1 4 0 6 3 2 2 2 0 1 1 1 1 1 1 1 1 1 2 2 1 2 1 1 3 1 1 1
Sample output:
4 10 22
-------------------------------------------------editorial-------------------------------------------------------------------------------
CHECK WHETHER 1 TO 10 CAN BE MADE OR NOT IF NOT THAN GIVE ANSWER AS IN CASE OF TEST CASE 1
ELSE
CHANCE OF 1 ST NUMBER NO TO FORM IS 10 ,THAN 11 , 22 , 33 , 44 , 55, 66 , 77 ...
100 111,222,333,444......
1000 1111,2222,3333.....
10000 11111 ,22222,33333.....
HENCE COUNT NO OF 0 1,..9 WHOSE VALUE IS LESS THAN WILL GIVE THE ANSWER ..
ALSO NOTE THAT NO OF ' 0 ' CAN BE 1 LESS THAN ANY OTHER NO ..
******************************************************CODE*****************************************
#include<iostream> using namespace std; #include<bits/stdc++.h> int main() { int t; cin>>t; while(t--) { int arr[11]; for(int i=0;i<10;i++) { cin>>arr[i]; } int ans=0; int cc=1; int i=0; int f=0; while(1) { if(i==0 ) { if(arr[i]<cc-1) { f=1; cout<<"1"; for(int j=1;j<cc;j++) cout<<"0"; } } else { if(arr[i]<cc) { f=1; for(int j=0;j<cc;j++) cout<<i; } } i++; i%=10; if(f==1) break; if(i==0) { cc++; } // cout<<"i "<<i<<" cc "<<cc<<endl; } cout<<endl; } }
No comments:
Post a Comment