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

×

Codeforces Question : Hometask

214B Hometask
My Solution : Link

I am getting wrong answer at test case no. 14. Also can anyone please explain the difference between the test case no 13 and 14 as they seem same to me.Please help.

Thanks in advance.

asked 29 Jan '17, 14:20

deepansh_946's gravatar image

2★deepansh_946
466
accept rate: 0%

edited 29 Jan '17, 14:22


There are a few bugs , some cases you missed :)

Bug 1 :

When you did this :

if(ans == 1)
{
for(int i=0;i<n;i++)< br=""> {
if(a[i]%3 == ans)
{
pos = i;
break;
}
}
// cout << ans << " " << a[pos] << endl;
for(int i=n-1;i>=0;i--)
{
if(pos!=i)
cout << a[i] ;
}
}

You've done for the case if there were some digits such that digit %3 == 1

But what happens if there isn't.

Try to think how to solve then ( Hint : You managed to do that for ans==2 )

This bug fails the code for tests like :

5
3 2 2 0 0

actual output : 300
your o/p : 32200

Bug 2 :

Even if you find a digit such that digit%3==1 , you should check are all the remaining digits 0 or not. This will prevent you from printing leading zeroes.

Your code fails this case :

3
0 0 1

actual : 0
your : 00

This may be the case for test case 14 where your code failed

Bug 3 :

Again when you did this :

for(int i=n-1;i>=0;i--)
{
if(i!=pos1 and i!=pos2)
cout << a[i];
}

You should take care about if all the other digits are 0 or not.

Your code fails this test :

4
0 0 1 1

actual : 0
your : 00

This may be the case for test case 14 where your code failed

Bug 4 :

Again here :

for(int i=n-1;i>=0;i--)
{
if(i!=ps)
cout << a[i];
}

You should check whether the other digits are all zero or not.

Your code fails this test :

3
0 0 2

actual : 0
your : 00

This may be the case for test case 14 where your code failed

I hope there are no more bugs .Hope this helps . Don't be disheartened by all these bugs. You'll obviously do better and learn from your mistakes :) Good luck :)

link

answered 29 Jan '17, 16:01

robin_0_chef's gravatar image

4★robin_0_chef
1962
accept rate: 50%

1

Thanks for pointing out my mistakes. :)

(29 Jan '17, 20:38) deepansh_9462★
1

Finally solved it. :)

(29 Jan '17, 22:05) deepansh_9462★
1

Great Job !! =D Carry on :)

(30 Jan '17, 23:33) robin_0_chef4★
toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×877
×682

question asked: 29 Jan '17, 14:20

question was seen: 549 times

last updated: 30 Jan '17, 23:33