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

×

help for bugcal

my code partially solved but not fully please tell on which test it went wrong I have tested 10001 90009 answer 0 mine . AND THE PASTED CODE HERE IS SHOWING SOME FOOL THINGS WHICH I DONOT HAVE IN MY CODE I PASTED IT HERE AND IT GET BAD LIKE #INCLUDE AND PLEASE UPVOTE SO I CAN ABLE TO UPLOAD CODE HERE

    #include <bits/stdc++.h>
    #define ll long long
    #define fast ios_base::sync_with_stdio(0)

     using namespace std;

      int main() {

fast;

ll t;
cin >> t;

while( t-- )
{
    ll num1 , num2 ;
    cin >> num1 >> num2 ;
    vector<int> v;
    int sum;
    while( num1 != 0 || num2 != 0 )
    {
        int r1 = num1 % 10;
        int r2 = num2 % 10;
        sum = r1+ r2;
        v.push_back(sum%10);
        num1 /= 10;
        num2 /= 10;
    }
    sum = 0;
    for( int i=0; i<v.size(); i++)
      {
        sum += v[i];
      }

    if( sum != 0 )
    {
        for( int i= v.size()-1; i>=0; i--)
            cout << v[i];
    }
    else
   {
        cout << 0;
    }
    cout << endl;
}
return 0;
}

asked 29 Oct '17, 00:00

geforce's gravatar image

2★geforce
496
accept rate: 0%

(29 Oct '17, 00:02) geforce2★

Mate, Following test case fails your solution

1

55 54

Correct answer = 9

Your answer = 09

Refer https://discuss.codechef.com/questions/115538/october-lunchtime-unofficial-editorials-first-two-problems if you feel any need :)

link

answered 29 Oct '17, 00:11

taran_1407's gravatar image

5★taran_1407
3.9k2387
accept rate: 22%

thanks taran

(29 Oct '17, 00:15) geforce2★

No problem.

(29 Oct '17, 00:16) taran_14075★

Why are you taking the sum? There is no need of it. You can just print all the digits one by one.

link

answered 29 Oct '17, 00:12

ramini's gravatar image

2★ramini
615
accept rate: 8%

for leading zeros

(29 Oct '17, 00:14) geforce2★

That's where the trouble is. :D

(29 Oct '17, 00:16) taran_14075★

remove leading zeros '0' or if all value is zero the print only one zero '0' if got the same problem

2

54 54

55 55

output

8

0

my code link https://www.codechef.com/viewsolution/15987621

link

answered 29 Oct '17, 14:46

mili22's gravatar image

3★mili22
261
accept rate: 33%

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:

×2,701

question asked: 29 Oct '17, 00:00

question was seen: 396 times

last updated: 29 Oct '17, 14:46