You are not logged in. Please login at www.codechef.com to post your questions!

×

# Birthday Candles - CANDLE

Please help me with my code, I am getting wrong answer. Please tell me some cases where my code fails and suggest ways to improve it.

//My Code

# include <iostream>

using namespace std;

int min_positive(int *a, int size_a){ int m = 9, index; for(int i = 1; i<size_a; i++){="" if(m="">a[i]){ m = a[i]; index = i; } } return index; }

int min_all(int *a, int size_a){ int m = 9, index; for(int i = 0; i<size_a; i++){="" if(m="">a[i]){ m = a[i]; index = i; } } return index; }

int main(){

int t;
cin >> t;
while(t--){
int *a = new int;
for(int i = 0; i<10; i++){
cin >> a[i];
}
int m,n;
m = min_positive(a,10);
if(a[m]==0){
cout << m << endl;
}
else{
a[m]--;
n = min_all(a,10);
m = m*10;
while(a[n]!=0){
m += n;
a[n]--;
n = min_all(a,10);
m *= 10;
}
cout << m+n << endl;
}
}
return 0;


}

asked 15 Jul '14, 00:05 12
accept rate: 0%

 1 http://ideone.com/IJBjZO i am getting wrong answer for this question. i have tested my code over 20 test cases and its giving correct answer. Can anyone check and give some test cases on which my program is giving wrong answer? answered 31 Dec '15, 23:45 820●2●12 accept rate: 3% 1 check this : 2 7 7 7 7 7 7 7 7 3 Your code gives 9000 as output while clearly the answer is 1000. (01 Jan '16, 01:34)
 1 @archit910 You may like to go through my solution :D https://www.codechef.com/viewsolution/7429820 answered 01 Jan '16, 13:05 781●8 accept rate: 7%
 0 in the function min_positive , in the for loop i think u should initiate i with 0 and not 1 i dont really understand what exactly you are trying to achieve though .Can you explain what you want to get as output ? answered 15 Jul '14, 00:50 0★sarath12 51●3 accept rate: 50%
 0 I am giving the idea @archit910 , @abhishek010594 .Check whether this is what you are doing? Now firstly zero is not a valid age. So if the digit 0 has zero frequency the minimum age that cannot be expressed is not 0. However if 1 or 2 or any other digit has the frequency 0, the minimum age that cannot be expressed is 1 or 2 or any of those digit. Now if this is the input: 1 0 0 0 0 0 0 0 0 0 then the minimum age that cannot be expressed is 1. Now if the input is: 2 1 1 1 1 1 1 1 1 1 then the minimum age that cannot be expressed is 11. So this is what you should do. Find the minimum frequency. If the minimum frequency is of a digit which is not zero, print that digit, minimum frequency times+1. If there are many digits with the minimum frequency print the minimum most digit. If the digit zero has minimum frequency then print 1 and 0s minimum frequency+1 times. So if the input is: 0 1 1 1 1 1 1 1 1 1 the output is 10 and if the input is : 1 2 2 2 2 2 2 2 2 2 then the output is 100. However if the input is 1 1 2 2 2 2 2 2 2 2 the answer is 11. That is why first check whether the minimum frequency is the frequency of any other digit other than 0. answered 01 Jan '16, 11:42 56●3 accept rate: 7%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,828
×1,919
×12
×5
×4

question asked: 15 Jul '14, 00:05

question was seen: 1,424 times

last updated: 01 Jan '16, 13:05