Page 3 of 12
Posted: Fri May 23, 2003 9:46 am
by Almost Human
I've tried but it is still WA until I change all unsigned long into float ...
now I got ACC ...
Thanks for the suggestion .
Posted: Fri May 23, 2003 7:02 pm
by Hisoka
are you sure, I just change %li to %lu at input variabel, I submit your program and give me AC.

Posted: Fri May 23, 2003 9:00 pm
by titid_gede
perhaps you only changed %li to %lu only for scanf. you didnt change another %li (printf).
Posted: Tue May 27, 2003 2:50 am
by passwd
hi, I'm trying to solve this problem too , but I'm getting WA and I don't
know why ??
someone can help me ??
[c]
#include <stdio.h>
/*#define DEBUG*/
long reverse(long n) {
long fator=1;
long aux=n,resp=1;
while(aux!=0) { fator*=10; aux = aux / 10; }
fator/=10;
/* printf("aux: %d fator:%d \n",aux,fator); */
do {
aux=n % 10;
resp = resp + aux * fator;
n= n / 10;
fator/=10;
} while(n!=0);
--resp;
return resp;
}
int palindrome(long n) {
long aux=reverse(n);
if(aux==n) return 1;
else return 0;
}
int main() {
int i,n;
fscanf(stdin,"%d",&n);
for(i=0;i<n;++i) {
long valor,inv,soma;
int nit=1;
fscanf(stdin,"%d",&valor);
inv=reverse(valor);
soma = valor + inv;
while(palindrome(soma)==0) {
++nit;
valor=soma;
inv=reverse(valor);
soma = valor + inv;
}
fprintf(stdout,"%d %d\n",nit,soma);
}
return 0;
}
[/c]
thanks !!
Posted: Tue May 27, 2003 2:51 am
by passwd
hi, I'm trying to solve this problem too , but I'm getting WA and I don't
know why ??
someone can help me ??
[c]
#include <stdio.h>
/*#define DEBUG*/
long reverse(long n) {
long fator=1;
long aux=n,resp=1;
while(aux!=0) { fator*=10; aux = aux / 10; }
fator/=10;
/* printf("aux: %d fator:%d \n",aux,fator); */
do {
aux=n % 10;
resp = resp + aux * fator;
n= n / 10;
fator/=10;
} while(n!=0);
--resp;
return resp;
}
int palindrome(long n) {
long aux=reverse(n);
if(aux==n) return 1;
else return 0;
}
int main() {
int i,n;
fscanf(stdin,"%d",&n);
for(i=0;i<n;++i) {
long valor,inv,soma;
int nit=1;
fscanf(stdin,"%d",&valor);
inv=reverse(valor);
soma = valor + inv;
while(palindrome(soma)==0) {
++nit;
valor=soma;
inv=reverse(valor);
soma = valor + inv;
}
fprintf(stdout,"%d %d\n",nit,soma);
}
return 0;
}
[/c]
thanks !!
10018
Posted: Wed Aug 20, 2003 12:09 pm
by kpras
[java] /**
* Description :
* Date :16.08.2003
* Status :
* @author Prashant Kumar(
prashkr@iitk.ac.in ,
kpras@email.com)
*/
import java.io.IOException;
import java.util.StringTokenizer;
class Main{
private String number;
Main(int number){
this.number = ""+number;
}
public static void main(String[] args)
throws IOException {
StringTokenizer token = new StringTokenizer(readInput() );
int count = Integer.parseInt(token.nextToken());
Main obj;
for(int i = 0; i < count; i++) {
obj = new Main(Integer.parseInt(token.nextToken()));
System.out.println(obj.getResult());
}
}//end of main
public static void test(){
Main obj = new Main(195);
System.out.println(obj.getResult());
obj = new Main(265);
System.out.println(obj.getResult());
obj = new Main(750);
System.out.println(obj.getResult());
}
public String getResult() {
boolean palendrome = false;
int count = 0;
while(!palendrome){
palendrome = isPalendrome(number = reverseAndAdd(number));
count++;
}
return count+ " "+number;
}
public boolean isPalendrome(String string){
boolean palendrome = true;
char[] array = string.toCharArray();
int length = array.length;
int half = length / 2;
for(int i = 0; (i < half) && (palendrome); i++) {
if(array
!= array[length -1 -i]) {
palendrome = false;
}
}
return palendrome;
}
public String reverseAndAdd(String number) {
int length;
char[] array = number.toCharArray();
char[] reverse = new char[length = array.length];
for(int i = 0; i < length; i++) {
reverse = array[length -1 - i];
}
return ""+(Integer.parseInt(number)+ Integer.parseInt(new String(reverse)));//""+ to convert the int to string
}
private static String readInput()
throws IOException {
StringBuffer buffer = new StringBuffer();
boolean done = false;
int read = System.in.read();
while( !done) {
if( read != -1)
{
buffer.append( (char)read );
read = System.in.read();
}
else
{
done = true;
}
}
return buffer.toString();
}//end of readInput()
}//end of class[/java]
What is the right output for the input 99 now?
Posted: Wed Nov 05, 2003 12:55 pm
by chanwen
I got confused now.
According to the problem description, "If the sum is not a palindrome, ..."
Doesn't the term "sum" mean I have to do "reverse and add" at lease one time?
However, my on-line judge's result varies from WA, Time Limit Exceeeded, Run Time Error, ....
And after I change my code for the already-palindrome input, I got Accepted.
So what on earth is the correct answer?
Posted: Sat Nov 08, 2003 4:03 pm
by Joseph Kurniawan
For each of the N tests you will have to write a line with the following data : minimum number of iterations (additions) to get to the palindrome and the resulting palindrome itself separated by one space.
See the word 'minimum'. That signals that the number of iteration might be zero (no iteration at all) because the objective is to make a palindrome out of the given input. If the input is already a palindrome, the objective is accomplished!!

Alright, a communicating misunderstanding.
Posted: Sat Nov 08, 2003 5:23 pm
by chanwen
Because when I see the word "sum," I directly guess I should deal with all input with "reverse and add" at least one time. I think the description should be clearfied about the proper output format when N is already a palindrome.
I am not a native English user, so sometimes the interpretion/translation makes little differences from original in some viewpoints. Is it possible to make the description more detailed so no one will ask again about this problem.
By the way, this problem became one in my C programming midterm this week. What a coincidence!
10018 RE why help me
Posted: Mon Nov 10, 2003 2:24 am
by problem
i dont understand why its runtime error.plz find out my prob and give me solution.
/* @JUDGE_ID: xxxxxx 10018 C++ */
#include<stdio.h>
#include<math.h>
int q=0;
long double fact(long double i);
main()
{
int z,q;
long double i,j,t;
scanf("%d",&z);
for(q=0;q<z;q++)
{
scanf("%Lf",&i);
t=fact(i);
printf("%.0Lf\n",t);
}
}
long double fact(long double i)
{
q++;
long double j,x[250],sum=0,a;
int p,t;
a=i;
for(t=0;i>=1;t++)
{
j=fmodl(i,10);
x[t]=j;
i=floor(i/10);
}
for(t=t-1,p=0;t>=0;t--,p++)
{
sum=sum+x[p]*(powl(10,t));
}
if(sum==a)
{
printf("%d ",q-1);
q=0;
return a;
}
return fact(a+sum);
}
Posted: Mon Nov 10, 2003 9:05 am
by sohel
Hi there,
Your program actually gets compile error.
You can not use fmodl, and other functions like that.
I have changed your code and got it AC.
1. Change long double to double.
2. Change fmodl to fmod.
3. Change Lf to lf.
Hope it helps.
Posted: Mon Nov 10, 2003 5:03 pm
by osan
i think if you dont wanna use
1. Change long double to double.
2. Change fmodl to fmod.
3. Change Lf to lf.
u can use unsigned long.
but u have to use %lu.
10018 at last ac
Posted: Tue Nov 11, 2003 4:57 pm
by bayzid
thank everybody to give infomation.at last i ac the problem
10018 Reverse and Add
Posted: Wed Dec 10, 2003 9:53 am
by WR
I thought problems 333 (ISBN) and 10018 (Reverse and Add) were
easy - ha!
Has anybody a suggestions for 10018?!
My input
195 -> 4 9339
265 -> 5 45254
750 -> 3 6666
2 -> 1 4
99 -> 6 79497
6 -> 2 33
4000000000 -> 1 4000000004
20 -> 1 22
100 - > 1 101
I got a WA for that. Then I ignored input that already is a
palindrome -> WA. Then I output zero iterations for that input, e.g.
99 -> 0 99, led to WA as well.
Where's my mistake?
Posted: Wed Dec 10, 2003 10:11 am
by sohel
Hi,
your input and output seems to be correct.
And if the original number is a palindrome then output 0 N
May be you made a mistake somewhere else.
Perhaps posting your code will be a good idea.
