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

×

Problem1 in Peer section

Sorry to bother you again but can plz help me understand ehy im getting WA for Problem 1(Problem code: CMB01) of peer section. Link to my submission: http://www.codechef.com/viewsolution/5260510 Thank you in advance again.

asked 02 Nov '14, 20:30

tataisap's gravatar image

1★tataisap
245
accept rate: 0%


Well,you are getting WA because your code for reversing the number is not actually reversing the number.after the execution of for loop the right most digit of the number is used in addition.i.e if the number is 12345,then in each iteration you are updating a1 as mod of number/10,i.e
iteration no.1 : a1=12345%10=5
iteration no.2 :a1=1234%10=4
iteration no.3 : a1=123%10=3
iteration no.4 : a1=12%10=2
iteration no.5 : a1=1%10=1
thus your reversing code is outputting the right most digit of number.Rather than writing
for(int i=0;a>0;i++)
{ a1=a%10;
a/=10;}
Try this
for(int i=0;a>0;i++)
{ a1=a1*10;
a1=a1+a%10;
a/=10;}
This will give you the reversed number.Do check it out.Do the same editing for other 'for' loops too.

link

answered 02 Nov '14, 22:49

ansh1star033's gravatar image

3★ansh1star033
20629
accept rate: 9%

its still not working!! :( Link: http://www.codechef.com/viewsolution/5262358

(03 Nov '14, 00:55) tataisap1★

Hey,why are you printing the reversed nos. i.e a and b,that is not asked.You have to give the output as asked in the question,just remove those printf's for integers separately,n only print the final sum.This should get you AC.Try it.

(03 Nov '14, 01:50) ansh1star0333★
(03 Nov '14, 13:30) tataisap1★

O sorry i had mistakenly deletedthe \n so it wasnt working now ive got it thank you very much:)

(03 Nov '14, 13:49) tataisap1★

Cheers! :-)

(03 Nov '14, 15:24) ansh1star0333★
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:

×740
×180

question asked: 02 Nov '14, 20:30

question was seen: 531 times

last updated: 03 Nov '14, 15:24