## 10018 - Reverse and Add

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10018 - Reverse and Add

Check My Submissions for the reason for your CE.
Check input and AC output for thousands of problems on uDebug!

scyphi
New poster
Posts: 1
Joined: Thu Jun 18, 2015 12:43 am

### Re: 10018 - Reverse and Add

Why is my code giving me wrong answer?

Code: Select all

``````/*Problem 10018*/
#include <stdio.h>

int palindrome(unsigned int);

int main() {

int num;
scanf("%d", &num);

while (num--) {
c = 0;
do {
c++;

}

return 0;
}

unsigned int reverse = 0, temp = added;
while (temp != 0) {
reverse *= 10;
reverse += temp % 10;
temp /= 10;
}

}

unsigned int reverse = 0, temp = added;
while (temp != 0) {
reverse *= 10;
reverse += temp % 10;
temp /= 10;
}
return added == reverse ? 1 : 0;
}
``````

Sifat_mbstu
New poster
Posts: 1
Joined: Wed Jun 17, 2015 7:30 pm

### Re: 10018 - Reverse and Add

I submit the following COde several days ago .....Sample input output everything is okay. But Verdict is COMPILATION ERROR...
it would be my pleasure if anybody Help.
My Code is:

Code: Select all

``````#include <stdio.h>
int main()
{
long long int n, rev,original,num,c,test_num;
int a;
scanf("%lld",&test_num);
for(c=1; c<=test_num; c++)
{
scanf("%lld", & n);
while(n!=rev)
{
original=n;
rev=0;
while (n!=0)
{
rev=rev*10;
rev=rev+n%10;
n=n/10;
}
if(rev==num)
{
break;
}
num=rev+original;
n=num;
}
printf("%lld\n",num);
}
return 0;
}
``````

palusijf
New poster
Posts: 1
Joined: Fri Oct 16, 2015 4:43 pm

### Re: 10018 - Reverse and Add

Hello,

All test are OK but I still have WA !
Could you help me please ?
Here the code :

Code: Select all

``````#include <stdio.h>
#include <stdlib.h>
int revNumber( long long n )
{
long long rev = 0;
while(n) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
int main()
{
int nbCase = 0, i = 0;
int count = 0;
long long n = 0, sum = 0;

scanf("%d", &nbCase);

for(i = 0; i < nbCase; i++) {
scanf("%lld", &n);
sum = n + revNumber(n);
count = 1;

while (revNumber(sum ) != sum) {
sum = revNumber(sum) + sum;
count += 1;
}
printf("%d %lld\n", count, sum);
}

return 0;
}``````
Last edited by brianfry713 on Tue Oct 27, 2015 3:22 am, edited 1 time in total.