CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » The Next Palindrome

The Next Palindrome

Problem code: PALIN

  • Submit
  • All Submissions

All submissions for this problem are available.

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

Input

The first line contains integer t, the number of test cases. Followed by t lines containing integers K.

Output

For each K, output the smallest palindrome larger than K.

Example

Input:

2

808

2133

Output:

818

2222

Warning: large Input/Output data, be careful with certain languages


Author: admin
Date Added: 1-12-2008
Time Limit: 9 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

sumarora @ 7 Jun 2009 03:22 AM

Can anyone tell me what is wrong with my output in the last submission. It works fine for hte sample output on my machine

jaganr @ 20 Jun 2009 02:27 PM

same holds good for me too. I suspect some error in the checking methodology. If not share the input for which the program failed with the mail being sent. This is fairly straight forward thing to do with java

sookie @ 18 Aug 2009 01:37 AM

Hi codechef folks !
Why the above prgram is giving NZEO(non-zero exit code) error ?It is working fine in my machine. May I know where is the bug in above program?

Thanks for looking into it !

#include #include #include

vickycodmaster @ 22 Aug 2009 12:53 AM
#include #include #include void main() { int n; clrscr(); cout<<"enter the no."; cin>>n; if(n<9) { cout<<"nn"; } while(n>9) { int m=0; int l=n; again:while(l>0) { l=l/10; m++; } int a[20],start=n; for(int j=0;j

does single digit number is

vickycodmaster @ 24 Aug 2009 11:18 AM
does single digit number is considered as palindrome number??

1: I believe the test input

kOrc @ 25 Aug 2009 03:40 PM
1: I believe the test input is using excessive line-breaks. This is causing runtime errors due to empty inputs. I am going to try my next submission with dealing with empty inputs. This is probably a language and input-method specific issue.

hey this code giving out put

rangudu @ 30 Aug 2009 10:08 PM

hey this code giving out put in my compiler

better check it suggest me if any mistakes

@ADMIN my code is workin fine

raviteja6771 @ 31 Aug 2009 02:20 AM

@ADMIN

my code is workin fine in my computer and its workin fine for abt 400 digits and more....

but wat is the problem i cant understand im getin runtime error......

plz reply....

@ravi The input can have

pmg @ 1 Sep 2009 07:54 PM

@ravi

The input can have numbers up to (and including) 1000000 digits; 400 digits is too little.

i think the longest number

sridarshan @ 1 Sep 2009 10:20 PM

i think the longest number you can store in c ,c++ is in "unsigned long int"

and it doesn't store upto 1000000digits

any clue????

any clue???? Try the Small

pmg @ 2 Sep 2009 01:16 AM
any clue???? Try the Small factorials problem ( http://www.codechef.com/problems/FCTRL2/ ). Check its tutorial :)

i m some problem in

ankit.it.mnit @ 2 Sep 2009 03:03 AM

i m some problem in understanding the last line of the problem.. just tell me is 100 a palindrome.

since hundred can be read as 00100.

No, 00100 has leading zeroes

triplem @ 2 Sep 2009 04:33 AM

No, 00100 has leading zeroes and is not a number.

 my code working fine in my

Pankaj139 @ 6 Sep 2009 11:03 PM

 my code working fine in my computer i am using devcpp but when i submit here it gave me compile error.. can any one tell me why

Please take a look at

admin @ 7 Sep 2009 02:19 PM

Please take a look at www.codechef.com/help for a sample solution in c or c++.

are there extra spaces in the

aansu @ 17 Sep 2009 03:33 PM
are there extra spaces in the input??? or each test case wil be in a single line without spaces..

There won't be any extra

admin @ 17 Sep 2009 03:59 PM
There won't be any extra spaces.

i m generating the next

dksahuji @ 21 Sep 2009 11:39 AM
i m generating the next palindrome but judge declines it........ #include using namespace std; int main() { char a[10]; int l,i,j; gets(a); for(l=0;a[l]!='';l++) ; for(i=0,j=l-1;ia[j]) a[j]=a[i]; else { a[j-1]++; a[j]=a[i]; } } for(i=l-1;i>=0;i--,l--) { if(a[i]!='0') break; else a[i]=''; } if(l>1) cout<

i checked for my 1000000 and

prasanna_ @ 26 Sep 2009 04:41 PM

i checked for my 1000000 and my running time s fast but not able to get the ans

my code s

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define fore(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define sz size()
#define all(a) a.begin(),a.end()
int main()
{
int t,flag=0;
long v,k;
vector<long> res;
cin>>t;
fore(z,0,t)
{
cin>>v;
if(v/10<1) cout<<v<<endl;
else
{
k=v;
flag=0;
while(flag==0)
{
k++;
stringstream ss;
string cal;
ss<<k;
cal=ss.str();
for(int i=0;i<=(cal.sz+1)/2;i++)
{
if(cal[i]==cal[cal.sz-i-1]) {flag=1;}
else { flag=0; break; }
}
if(flag==1) {res.push_back(k); }
}
}   
}
fore(i,0,res.sz) cout<<res[i]<<endl;
return 0;
}

It says the number can be

triplem @ 27 Sep 2009 08:03 AM

It says the number can be 1000000 digits long, not just 1000000 which is only 7 digits long.

i am not able to understand

ajit @ 28 Sep 2009 06:45 PM
i am not able to understand how to input such a large value.

can anyone plz tell me wts

sitaram @ 30 Sep 2009 07:56 PM

can anyone plz tell me wts wrong with this code

a compiler error is being shown

import java.io.*;
import java.lang.Math;

class Enter
{
int rev(int num)
{
int s=0;
int len=String.valueOf(num).trim().length()-1;
while(num>0)
{
int r=num % 10;
num=num/10;

s=s+r*(int)Math.pow(10,len);
len--;
}   
return s;
}   
void find(int arr[])
{
for(int i=0;i<arr.length;i++){

int num1,flag=0,temp=arr[i];
temp++;
do{            
num1=rev(temp);
int l=String.valueOf(num1).trim().length();
if(temp==num1&&l!=1){                     
System.out.println();   
System.out.println(temp);
flag=1;
}
else{                
temp++;
}     

}while(flag==0);
}

}

void input() throws java.lang.Exception
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int tot=Integer.parseInt(str);
int[] arr;            
arr = new int[tot];
for(int i=0;i<tot;i++){
System.out.println();
str=br.readLine();       
arr[i]=Integer.parseInt(str);
}

find(arr);

}

}



class Palindrom1{
public static void main (String[] args) throws java.lang.Exception
{
Enter obj= new Enter();
obj.input();
}
}   




Please read the FAQ and the

i0exception @ 30 Sep 2009 08:05 PM

Please read the FAQ and the Sample Solutions

@admin wats the limit for

shaileshbhat @ 6 Oct 2009 06:56 PM

@admin

wats the limit for test cases  ?

9 seconds

admin @ 6 Oct 2009 07:14 PM

9 seconds

actually i talkin about max

shaileshbhat @ 6 Oct 2009 07:55 PM

actually i talkin about max value for first line of input.

10

admin @ 6 Oct 2009 08:17 PM

10

@admin, max value for first

shaileshbhat @ 6 Oct 2009 08:41 PM

@admin,

max value for first line of input is not specified in the problem..

thank u.

shaileshbhat @ 6 Oct 2009 08:42 PM

thank u.

@admin, i submitted solution

shaileshbhat @ 13 Oct 2009 10:41 PM

@admin,

i submitted solution for this problem,it shows wrong answer,can it possible to tell,is it any logical error or error in format of output wat i m printing..ie spacing or new line.. soln id is110546,110544

 

So long as your output is in

admin @ 13 Oct 2009 11:12 PM

So long as your output is in accordance with what is specified in the output format, there should be no problems. There are no issues with newlines.

@admin, thank you,finally i

shaileshbhat @ 14 Oct 2009 01:29 AM

@admin,

thank you,finally i got where i m wrong.

public class Demo { public

rajeev ranjan @ 15 Oct 2009 12:05 AM
public class Demo { public static void main(String[] args) { final double FEE = 0.5; Scanner sn = new Scanner(System.in);; double balance=0.0,withdrawl=0.0; System.out.println("Enter withdraw and balance"); withdrawl = sn.nextDouble(); balance = sn.nextDouble(); if(((withdrawl % 5) == 0) && (balance > (withdrawl + FEE)) && (balance>=0 && balance<=2000) && (withdrawl>=0 && withdrawl<=2000)) { balance = balance - (withdrawl + FEE); } System.out.printf("Your current balance is:=%.2f",balance); } } plz help me out ti find the bug

admin, can you tell me what

mohammad @ 26 Oct 2009 09:50 PM

admin,

can you tell me what is the complation error my submission is giving. It compiles fine on VC++

You have submitted a blank

admin @ 27 Oct 2009 03:37 PM

You have submitted a blank file. That is the reason why it is giving a compile error.

i have written my program in

raj_daiict @ 28 Oct 2009 05:23 PM

i have written my program in java ...but after submitting its showing following compilation error....but its wrking fine on my pc...smbdy plzz help....

sources/Main.java:9: class Palindrome is public, should be declared in a file named Palindrome.java public class Palindrome { ^ 1 error

Read the FAQ.

triplem @ 29 Oct 2009 07:33 AM

Read the FAQ.

@admin can u tell me for what

Zahid1991 @ 4 Nov 2009 12:02 AM

@admin

can u tell me for what input am i getting wrong answer???

soln id : [120718]

no problem...got it...

Zahid1991 @ 4 Nov 2009 12:29 AM

no problem...got it...

@admin. I tried my code on

bharatj @ 27 Nov 2009 01:08 AM

@admin.

I tried my code on all types of inputs. It works fine in my sys. I checked for values having 1000000 digits too. But its not getting accepted here. It says wrong answer. Atleast can you tell me which case my code is failing.

Thank you.

@admin I am printing the

bharatj @ 27 Nov 2009 01:17 AM

@admin

I am printing the output as an when I process a test case, should I print the results after processing all test cases?

Thanks

No, printing them the way you

admin @ 27 Nov 2009 02:22 AM

No, printing them the way you are doing is fine. You might want to take at corner cases. Large test cases need not necessarily be the correct way to test your program.

Got it admin. Minor bug. I am

bharatj @ 27 Nov 2009 09:13 AM

Got it admin.

Minor bug. I am happy now. Thanks anyway.

i am getting a wrong answer

deepanshu gupta @ 6 Dec 2009 05:18 PM

i am getting a wrong answer all the time. could you tell me the the common places where mistakes are made in this problem. i've tried single digit numbers, all 9s and a few random numbers.

my approach is to copy the first half of the string to the last (after reversing). if the resulting number is smaller than the orig no. i add 1 to the first half of the number and copy again.

also, should the new line be printed at the end of the last input?

@ admin can u please suggest

spunkycoder @ 13 Dec 2009 03:02 AM

@ admin

can u please suggest the problem in my latest code ... i have tried different variants but each time i am getting the same Runtime Error(OTHER). Also, what kind of runtime is the code giving, to be exact ?

how can a input of 1000000

gauravgaba @ 20 Dec 2009 03:24 PM

how can a input of 1000000 digits can be taken in language c

 

can anyone help?????????

A char array?

triplem @ 20 Dec 2009 04:39 PM

A char array?

bt can an array be declared

gauravgaba @ 21 Dec 2009 12:51 AM

bt can an array be declared to hold 1000000 elements

 

it shows error on my compiler array size too large

will it wrk on cc compiler????????????????????

bt can an array be declared

gauravgaba @ 21 Dec 2009 04:13 AM

bt can an array be declared to hold 1000000 elements



it shows error on my compiler "array size too large"

will it wrk on codechef compiler????????????????????

Declare it outside your

admin @ 21 Dec 2009 04:50 AM

Declare it outside your function, as a global entity.

i think my code is correct

Dalchand @ 21 Dec 2009 10:50 PM

i think my code is correct ... why it is showing Wrong Answer please help

It is showing Wrong Answer

triplem @ 22 Dec 2009 04:54 AM

It is showing Wrong Answer because it is not correct, so you shouldn't think it is :P

someone please send me some

Dalchand @ 22 Dec 2009 06:10 AM

someone please send me some test cases id: dalchand@iitkgp.ac.in ... with answer :)

@stephen no it is correct...

Dalchand @ 22 Dec 2009 06:12 AM

@stephen no it is correct... :P

can someone tell me about the

Dalchand @ 22 Dec 2009 02:58 PM

can someone tell me about the input/output format... i'm new at codechef :(

I'm taking iput as: //MAX =

Dalchand @ 22 Dec 2009 03:02 PM

I'm taking iput as:

//MAX = 500000

scanf("%d",&u);
c = getchar();
while( u > 0){
n = 0;
do{
c = getchar();
if(c == 'n')
break;
if(n < MAX-1)
A[n]=c;
else
B[n-MAX+1]=c;
n++;
}while(c!='n');
if(n < MAX){
A[n]='';
B[0]='';
}
else{
A[MAX-1]='';
B[n-MAX+1]='';
}

//and puting output as

printf("%s%sn",A,B);

// A and B are char array each of size MAX

it this the correct way?

sorry ? mark is null

Dalchand @ 22 Dec 2009 03:03 PM

sorry ? mark is null character ' '

' \ 0 '

Dalchand @ 22 Dec 2009 03:04 PM

' 0 '

Please stop spamming. Your

admin @ 22 Dec 2009 03:09 PM

Please stop spamming. Your code is incorrect and no one is going to mail you the test cases :) Please check out www.codechef.com/wiki . Input is provided via stdin and you have to print the output to stdout.

@Aniruddha : i submitted a

Sudheerkumar @ 23 Dec 2009 01:37 AM

@Aniruddha :

i submitted a solution in JAVA which is working fine in my pc. Here its giving a runtime error - NZEC. I looked at the error definition and catcheed all the errors. But still get the same error. Can you please tell me what is the exact problem with my code???

The first thing I did was

triplem @ 23 Dec 2009 03:26 AM

The first thing I did was test your code on an input of maximal size. It threw an exception. Surely you've tried that?

Is there anyone who solved

ashwin_jain @ 23 Dec 2009 04:35 PM

Is there anyone who solved this one in java. Mine code is working fine on my computer (even with 1000000000 digits input also), but I am getting time limit exceed. 


@admin please check my

Dalchand @ 5 Jan 2010 11:42 PM

@admin please check my solution :) my submission ID is 160207 ... tell me if there is any problem with input/output format..

The input / output format is

admin @ 6 Jan 2010 04:54 PM

The input / output format is mentioned in the problem statement. Please check it yourself.

@admin hii, i checked my code

dabbcomputers @ 31 Jan 2010 07:30 PM

@admin

hii,

i checked my code to many time but it is always giving wrong answere can u pls tell me where my code is wrong.

my code giving correct answer on my pc. my submision id is 176543

No, it is not giving the

triplem @ 1 Feb 2010 01:07 AM

No, it is not giving the correct answer on your pc; you can't have tried many test cases at all. Almost every single one I tried failed.

I input 9 as a test case, and the program exits before I have a chance to enter other test cases. I enter 100 and get 111 when the answer is of course 101. I enter 99, and the program quits again..

@admin:My code is working

mukesh_singh @ 8 Feb 2010 08:06 AM

@admin:My code is working fine in my PC having gcc And also  giving output for 10 test cases in 0.004 secs but is showing time limit exceed after submission ..Plz tell me where I am making mistake.I am new to codechef >Help!

What test cases did you try?

triplem @ 8 Feb 2010 09:36 AM

What test cases did you try? The most obvious test case to try that may take some time is the largest possible, ie something with 1000000 digits. You obviously haven't tried that :P

@admin hello , can you please

composer @ 8 Feb 2010 04:02 PM

@admin

hello , can you please tell what is the problem in my solution . my solution ID is 183285. thanks for your time .

@stephen :Thanks for ur help

mukesh_singh @ 8 Feb 2010 08:47 PM

@stephen :Thanks for ur help I got my mistake.

what is the range of t ??

composer @ 10 Feb 2010 10:17 AM

what is the range of t ??

Getting a wrong answer for

avaneja @ 10 Feb 2010 04:55 PM

Getting a wrong answer for the submission 185356.

Anyone willing to tell me why ?

@admin,@stephen,@Aniruddha ca

SumitRathi @ 12 Feb 2010 10:58 PM

@admin,@stephen,@Aniruddha

can u please tell what is the problem with code

submission id 187096 and 187105 .

Running fine in my computer even for more larger values than the specified limit.


No it isn't. Your code

triplem @ 13 Feb 2010 02:09 AM

No it isn't. Your code doesn't even work on an input of 100 digits, let alone a million digits.

sorry my mistake ... its

SumitRathi @ 13 Feb 2010 09:40 AM

sorry my mistake ... its million digits not million number ... extremely sorry

@admin, @stephen Any guesses

avaneja @ 13 Feb 2010 08:27 PM

@admin, @stephen

Any guesses to what may be wrong with the submission 185356 ?

@stephen,@Aniruddha please

SumitRathi @ 13 Feb 2010 09:01 PM

@stephen,@Aniruddha

please check i have changed code but this time system is giving TLE...can u tell me

problem is Slower I/O or my Logic. So that i can work on that part.

submission id 187507

@stephen,@Aniruddha submissio

SumitRathi @ 14 Feb 2010 12:38 AM

@stephen,@Aniruddha

submission id is  187589

@stephen,@Aniruddha PLEASE

SumitRathi @ 14 Feb 2010 12:40 AM

@stephen,@Aniruddha

PLEASE IGNORE MY ABOVE TWO POST AND

please check i have changed code but this time system is giving TLE...can u tell me

problem is Slower I/O or my Logic. So that i can work on that part.

submission id is  187589

Whats wrong in this code for

vaibhav_89 @ 22 Feb 2010 01:51 AM

Whats wrong in this code for "The next palindrome"

My code is

#include<stdio.h>

#define max 10

int check(long int val);

int main()

{int t,i,j;

long int k[max];

scanf("%d",&t);

for(i=0;i<t;i++)

scanf("%ld",&k[i]);

 

for(i=0;i<t;i++)

{k[i]++;

if(k[i]<1000000)

{while(!check(k[i]))

k[i]++;

printf("%ldn",k[i]);}

}

return 0;

}

 

int check(long int val)

{int c=0;

long int a=val;

while(a!=0)

{c=c*10+a%10;

a=a/10;

}

if(c==val)

return 1;

else

return 0;

}

 

Its running on my pc...but i am not able to submit this code....help me

Please don't post code. Read

triplem @ 22 Feb 2010 02:07 AM

Please don't post code. Read the FAQ. For one thing, your code will obviously fail when there are more than 10 test cases. It also has no hope on an input with 1000000 digits.

#include<stdio.h>#include<str

prashant11132 @ 24 Mar 2010 10:26 AM

#include<stdio.h>
#include<string.h>
int main(void){
int t,num,n,j,len;
char str[100],str1[100];
scanf("%d",&t);
while(t){
scanf("%d",&num);
for(num++;;num++){
n=num;
j=0;
while(n != 0){
str[j++]=(n%10)+48;
n/=10;
}
str[j]='';
len=strlen(str);
//strcpy(str1,str);
//strrev(str1);
strlen(str);
j=0;
while(len--){
str1[j++]=str[len];
}
str1[j]='';
if(strcmp(str,str1)==0){
printf("%sn",str);
t--;
break;
}



}
}
}


can u temme wat's wrong in da code..i m gettn da answere but its not gettn accepted here..

can any one let me know how

vikasssa @ 24 Mar 2010 11:42 AM

can any one let me know how to take input such a number having million digits?

if i take it in array,then how should i proceed?

i'm new to codechef.....plz help me

plz help me

vikasssa @ 24 Mar 2010 12:28 PM

plz help me

i would love to read more

kalos @ 24 Mar 2010 04:21 PM

i would love to read more from you on this

Can anyone find the error in

eswaramaharaja @ 14 Apr 2010 01:07 AM

Can anyone find the error in my program.............

http://www.codechef.com/viewsolution/231494

Somebody who has solved the

javadecoder @ 30 Apr 2010 10:38 PM

Somebody who has solved the problem please tell me in which test case my program is not giving the right output.

What about the single digit

javadecoder @ 30 Apr 2010 11:08 PM

What about the single digit numbers??

Do we have to simply print a number just greater to them(For 5,it will be 6 and For 9,it will be 11)??

i'm getting correct answer

akshit24 @ 25 May 2010 12:07 AM

i'm getting correct answer according to following program but its not getting accepted here.

Can somebody find out d mistake in the following:

 

                                                                     



#include<iostream>
using namespace std;
int main()
{
long long int m,n,i,r,j,s,t,a[500];
cin>>t;
for(i=1;i<=t;i++)
{
cin>>n;
n=n+1;
for(j=1;j<=100000;j++)
{m=n;
s=0;
while(n!=0)


{r=n%10;
s=(s*10)+r;
n=n/10;}
if(m==s)
{
a[i]=s;
j=100001;}
m++;
n=m;}
}
for(i=1;i<=t;i++)
cout<<a[i]<<endl;
return 0;
}






100000 digits means value or

deathsmoke @ 11 Jun 2010 09:45 PM

100000 digits means value or 1000000 digits? how is it possible to deal with such large values, do we need to store it as character array then do calculations??

It says digits; it means

triplem @ 12 Jun 2010 03:23 AM

It says digits; it means digits.

im getting a runtime (other)

deathsmoke @ 12 Jun 2010 02:00 PM

im getting a runtime (other) error, can you please point out what that error may be, its working fine on codeblocks on windows using default compile which i think is g++

here my code:

 

#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

void add(string &,int ,int ,unsigned long  int&);
int main(){
unsigned long long int k;
string palin;
unsigned long int digits;
unsigned long int counter=0;
unsigned int temp;
int consec_tries=0;
char c,d;
//char no[50]={''};
cin>>k;


while(k--){
consec_tries=0;
counter=0;
cin>>palin;
digits=palin.length();

add(palin,1,digits-1-counter,digits);

while( counter < digits/2 ){
c=palin[digits-counter-1];
d=palin[counter];
if( c==d ) {
consec_tries++;
counter++;
}

else if( c<d ){
//palin+= palin[counter] - palin[digit-counter-1];
palin.at(digits-counter-1)=palin.at(counter);
counter++;
consec_tries=-100;

}

else {//c>d

//palin+=(palin[counter]+10- palin[digits-1-counter])* temp;
palin[digits-counter-1]=palin[counter];

counter++;
add(palin,1,(digits-counter-1),digits); //add 1 at digits-counter pos ie next position
consec_tries=-100;


}

if(consec_tries == (digits/2))
break;

else if( counter==(digits/2)){

counter=0;
consec_tries=0;
continue;
}


}

cout<<palin<<endl;

}
return 0;
}

void add(string &pal,int no,int pos,unsigned long int &no_digits){
int val,counter=0;
char c=pal[pos];
string temp="1";
//c=cstr[pos];
if( pal.at(pos) != '9'){

pal.at(pos)=atoi(&c)+no+'0';

}

else{
while(pal.at(pos)=='9' && counter<pal.length()){
cout<<"hell"<<endl;
pal.at(pos)='0';
pos--; //since higher digit is at lower index
counter++;
}
if( pos>-1)
pal[pos]=atoi(&pal[pos])+no+'0';
else{
pal=temp.append(pal);
no_digits++;
}
}
}

@admin, Well I have tried

Triton @ 17 Jun 2010 06:48 PM

@admin,

Well I have tried this problem out and it shows wrong answer, could you please tell me for what inputs it gives the wrong answer......

my solution id is 270161...plzz help, thanks in advance

@Sarthak. well try out the

raman bhatia @ 17 Jun 2010 10:57 PM

@Sarthak. well try out the cases like 99,999 etc.. and check what result u get for'em

I am keeping on getting wrong

turing.acm9 @ 1 Jul 2010 12:21 PM

I am keeping on getting wrong answer. Pl help my submission id is 274092

I resubmitted but still

turing.acm9 @ 1 Jul 2010 01:18 PM

I resubmitted but still gettin the wrong answer. Admin Pl help my submission code is 274109

@karthik Check your output

javadecoder @ 1 Jul 2010 02:56 PM

@karthik

Check your output for 9,191,1991,19991...

i am submitting the following

ALCHEMIST_PS @ 12 Aug 2010 03:55 PM

i am submitting the following code ..... but online judge is displaying it as a wrong answer ..... its showing the correct output in my system ........ i am using dev c++ as a compiler.... please help me out ........

#include<iostream>
int main(void)
{long long int a,n,i=0,c;
int t,j;
std::cin>>t;
for(j=1;j<=t;j++)
{ std::cin>>n;
if(n>1000000)
{ break;
}
while(1)
{i=0;
n++;
c=n;
while(c!=0)
{   a=c%10;
i=i*10+a;
c=c/10;

}

if(n==i)
{ std::cout<<n;
break;
}
}
if(j<t)
std::cout<<"n";
}
return 0;
}

@PRATHMESH SWAROOP: Please do

bhaskar_rak @ 17 Aug 2010 03:50 PM

@PRATHMESH SWAROOP: Please do not post your code here. Also please read the problem statement atleast 3 times, it will help you. It is "1000000 digits" not the number "1000000". So think about how to take input as long as 1000000 digits first and then try to find the next palindrome. Hint: You might have a look at fgets().

  in my computer ri8 input n

Abhi1289 @ 22 Aug 2010 03:30 AM

 

in my computer ri8 input n output is coming.....but here says wrong.

can u PLZZZZZ  tell me what is wrong in my code(in C)...

#include<stdio.h>

int main()

{    int s,p;

scanf("%d",&p);

for(s=0;s<p;s++)

{

long int n,i;

scanf("%ld",&n);

for(i=n+1;i<1000000;i++)

{

long int m,r=0,k;

m=i;

while(i!=0)

{

k=i%10;

r=10*r+k;

i=i/10;

}

if(m==r)

{printf("%ldn",m);break;}

i=m;

}

}

return(0);

 

}

#include<stdio.h>
int main()
{    int s,p;
scanf("%d",&p);
for(s=0;s<p;s++)
{
long int n,i;
scanf("%ld",&n);
for(i=n+1;i<1000000;i++)
{
long int m,r=0,k;
m=i;
while(i!=0)
{
k=i%10;
r=10*r+k;
i=i/10;
}
if(m==r)
{printf("%ldn",m);break;}
i=m;
}
}
return(0);
}

 

You didn't even read the

triplem @ 22 Aug 2010 06:23 AM

You didn't even read the comment directly above yours..

thanx.....4 reply.

Abhi1289 @ 22 Aug 2010 08:25 PM

thanx.....4 reply.

My solution is running fine

andipandi @ 8 Sep 2010 09:01 PM

My solution is running fine on all inputs locally.

I checked that each number (string) I produce is a palindrome.

By my algorithm, I am pretty certain to make sure that I return the smalles number possilbe.

Also (which I overlookd) now I add 1 before I run the algorithm in order to get a larger solution.

Still.. wrong answer. Everything runs fine with my test cases.

I tried:            and got:

30

100
10000001
1000001
1
9
919
333999
33999
33399
9911
9991
911
199
1999
9876
987
1
9
0
8008
8007
1234
101
102
999
9999
998
948
1000
100
10001

 

101
10011001
1001001
2
11
929
334433
34043
33433
9999
9999
919
202
2002
9889
989
2
11
1
8118
8008
1331
111
111
1001
10001
999
949
1001
101
10101

Which seems fine. Still no luck. Any ideas?

 

My code in Java crashes with

chandniverma @ 14 Sep 2010 10:21 PM

My code in Java crashes with NZEC. I tried giving a million digit number as an input, and it ran on my system(in 9 minutes altough) , i tried all other cases i could think of and they ran as expected.

So, it should be able to run on the judge and should be declared as TLE but its reporting a runtime error in the first place.

admin please give some directions. Last Submission ID: 332042

I checked my code for smaller

rampage @ 23 Sep 2010 08:51 PM
I checked my code for smaller inputs.It gives the correct answer.It even runs for a million digit number in less than half a second.But my answer is incorrect according to the judge.I think the error is in the way I take input. Is this wrong? while((ch=getchar())!='n') num[len++]=ch-'0';

Yes, that definitely won't

triplem @ 24 Sep 2010 03:12 AM

Yes, that definitely won't work, since new lines have an \r character in them (see the FAQ).

#include <iostream>#include

eaglex @ 10 Oct 2010 01:44 AM


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int palin (int);

int main()
{
int m;
int o;
vector <int> u;    // TO STORE INPUT NO.
cin>>o;

for (int e = 0; e < o; e++){
cin>>m;
u.push_back(m);
}   

for (int h = 0 ; h < u.size(); h++){
int t = u[h] ;     // No which will be checked for palindrome
int b = palin(t);//Calling function 'palin' which'll give next palindrome No.
cout<<endl<<b<<endl;
}   
return 0;
}
/*.......................................................
FUNCTION TO CHECK NO IS  PALINDROME OR NOT
...................................................*/  

int palin(int i){
int t = i+1;
int u = i+1;
int j = 0;
int k = 0;
/* LOOP TO CALUCATE NO OF DIGITS */   
while (u > 0){
u = u/10;
k++;
}
/*LOOP TO GET REVERSE NO.*/
while (t > 0){
k--;
int a = t%10;
t = t/10;
j = j + a*pow(10, k);
}
if ((i+1) == j){
return j;
}
else palin(i+1);   
}

This code is working according question on my PC, but here it is giving wrong answer,please specify the inputs for which it's not working properly.

Did you read how big K can

triplem @ 10 Oct 2010 06:10 AM

Did you read how big K can be?

@Admin, when i submitted my

indontop @ 12 Oct 2010 03:56 PM

@Admin,

when i submitted my soln, i got internal error occured in the system error . when does that happen ?

My code is working perfectly

AbhishekJha @ 26 Oct 2010 12:52 AM

My code is working perfectly fine in turbo c compiler. but when m submitting the soln it gives runtime error.

plz help me how can i know and rectify my error. iwant to know where actually error lies

Accepted Solutions

sanjaynambiar @ 1 Nov 2010 12:20 AM

Accepted Solutions Wrong??!!

My code is wworking fine with all test cases i tried. But I'm getting wrong answer again and again.

So I took 2 solutions from the accpeted ones and the gave the same input set to both. Interestingly both generated different outputs!!!! And worst of all for the sample inputs given above they are not producing the above mentioned outputs!!! PLZ CHECK!!!!!!!!!

It only took me about 30

triplem @ 1 Nov 2010 02:42 AM

It only took me about 30 seconds of testing random inputs on your code to find one that didn't work. I entered 9798 and you print 9879, which isn't a palindrome.

As for accepted solutions being wrong; it is possible an accepted solution can give a wrong answer to a particular test case, but it is also easily possible you are testing them incorrectly. What solutions do you think are incorrect, and on what input?

@admin, Well I have tried

tornado002 @ 5 Nov 2010 10:59 AM

@admin,

Well I have tried this problem out and it shows wrong answer, could you please tell me for what inputs it gives the wrong answer......

plzz help, thanks in advance,....

my solution is>>>http://www.codechef.com/viewsolution/373799......

One immediate mistake is that

triplem @ 5 Nov 2010 11:14 AM

One immediate mistake is that your program doesn't allow enough space to read in a string with a million digits.

@Stephen i am declaring a

tornado002 @ 5 Nov 2010 11:48 AM

@Stephen

i am declaring a character array f[1000000] so why is it not providing enough space????????help!!!!!

An array of length 1000000

triplem @ 5 Nov 2010 01:06 PM

An array of length 1000000 can hold a string of at most 999999 digits. That's the first thing anyone learns in C :P

sry for my

tornado002 @ 5 Nov 2010 01:28 PM

sry for my blunder!!!!!!!!!!!!

still wrong answer plz

tornado002 @ 5 Nov 2010 01:51 PM

still wrong answer plz help!!!!!!

http://www.codechef.com/viewsolution/373888

plzzz help admin still i am

tornado002 @ 6 Nov 2010 12:58 PM

plzzz help admin still i am gettting a wrong answer...

http://www.codechef.com/viewsolution/374688

hello admin and

algomm @ 8 Nov 2010 01:04 AM

hello admin and stephen

 

could you please tell the problem with my code.
my solution is at: http://www.codechef.com/viewsolution/376143

Its showing wrong answer but seem to show results for test cases mentioned in problem and in the discussions so far.

Plz help.
Thanks in advance.

I'm afraid you'll kick

triplem @ 8 Nov 2010 04:59 AM

I'm afraid you'll kick yourself when you see it :) Try reading your code, one line at a time, from the top..

yeah really kicked

algomm @ 8 Nov 2010 05:27 AM

yeah really kicked myself!!!

thanks by the way.

wht abt my query my solution

tornado002 @ 8 Nov 2010 01:41 PM

wht abt my query my solution is http://www.codechef.com/viewsolution/374688 why i am getting a wrong answer????plz help stephen.........thanx in advance......

@admin:

dhiman_nikhil @ 17 Nov 2010 02:00 AM

@admin: http://www.codechef.com/viewsolution/370225 submitted by sanjaynambiar is giving wrong output , so how can this be submitted succesfully

Ex: Output by his algo

k value = 289882

Actual output = 290092 [Sanjaynambiar algo gives this answer]

Expected 289982[ Bcz that no. is nearer to k value]

 

I didn't  checked it out for other successfull submitters, but if your script passes that type of mistake than it will always give wrong answer if someone submitted the correct solution ...

 

 

Any correct solution will

triplem @ 17 Nov 2010 09:34 AM

Any correct solution will always be accepted. While the judge's test cases try to cover as many possibilities as possible, it is obviously impossible to test every single test case - so it is always possible that a wrong solution could be judged correct, while failing on some test cases that weren't provided.

I really don't know what are

dhiman_nikhil @ 17 Nov 2010 04:33 PM

I really don't know what are your test cases, again one of your succesfull submitter fails some the basic value spandan dutta

http://www.codechef.com/viewsolution/354625

Value  -- Next Palindrome

100--101 R
101--201 W
102--201 W
103--201 W
104--201 W
105--201 W
106--201 W
107--201 W

108--201 W

109--111 R
110--111 R

 

R-Right answer

Q - Wrong answer

 

 

 

*Q--> W -- Wrong

dhiman_nikhil @ 17 Nov 2010 05:35 PM

*Q--> W -- Wrong

That's not the output that

triplem @ 18 Nov 2010 01:39 AM

That's not the output that program produces. You must be testing it incorrectly.

  Sory for that compare the

dhiman_nikhil @ 18 Nov 2010 05:34 PM

 

Sory for that compare the old file with new one.

 

 

I have one query..

 

Test case

1. No of test cases 100

Value is in 10^6 digits

spandan dutta time in execution

http://www.codechef.com/viewsolution/354625

real    0m5.023s
user    0m4.660s
sys    0m0.328s

 

My solution time in execution

http://www.codechef.com/viewsolution/381290


real    0m4.696s
user    0m3.664s
sys    0m0.324s

 

Still on codechef execution time of spandan is 0.00 and mine is 0.20.

Is that i am missing something, please do let me know as i am quite curious to know my mistake .

Can anyone tell me what is

siddhartha10 @ 19 Nov 2010 03:49 AM

Can anyone tell me what is WRONG in this code???

At least gcc cant find any.....

http://www.codechef.com/viewsolution/381453

Please don't post your code

triplem @ 19 Nov 2010 05:47 AM

Please don't post your code in the comments. Read the input constraints again.

I tested my code for all

kislaykishore @ 30 Nov 2010 06:55 PM

I tested my code for all inputs here... It gives correct output...

Bur still getting a wrong answer error....

http://www.codechef.com/viewsolution/385927

http://www.codechef.com/views

kriateive @ 7 Dec 2010 07:32 PM

http://www.codechef.com/viewsolution/392720 which test case is my code failing!! somebody help!!

It is easy to find test cases

triplem @ 9 Dec 2010 09:55 AM

It is easy to find test cases it fails on if you test systematically. For example, it doesn't work on an input of 9..

@admin: I checked some posted

tarun_kumar @ 15 Dec 2010 04:03 PM

@admin:

I checked some posted codes randomly and found following errors.

if we give input 00100

output should be 101.

but program was giving output 00200.

if input is 876547982
output should be something greater than this number, but the output was.

876545678

admin its my humble request please revise the test cases and look into all the codes again.

thank you

The first input you provided

triplem @ 16 Dec 2010 02:32 AM

The first input you provided is not an integer, and the problem says you should enter an integer.

As for the second; I have already talked about this in earlier comments. No matter what test cases are provided, it is always possible for a wrong program to be accepted. Just make sure yours is right and you will always be accepted.

My program is working for all

apoorvpurwar @ 16 Dec 2010 07:12 AM

My program is working for all possible test cases, even for the cases for which some of the accepted programs are not working(as stated in comments) , but still i am getting wrong answer,,,please help..!!!

My code is available at..."http://www.codechef.com/viewsolution/400176".

Did you not read how big K

triplem @ 16 Dec 2010 07:24 AM

Did you not read how big K could be?

@Stephen..I converted all my

apoorvpurwar @ 16 Dec 2010 08:20 AM

@Stephen..I converted all my variables to long still i am getting the wrong answer.

Modified code available at..http://www.codechef.com/viewsolution/400187.

and thanks for your prompt response.

Why would long help? I'll say

triplem @ 16 Dec 2010 08:25 AM

Why would long help? I'll say it again, have you read how large K can be?

so is there anyway by which

apoorvpurwar @ 16 Dec 2010 12:51 PM

so is there anyway by which this one can be solved without using a character array.

You're going to have to store

triplem @ 16 Dec 2010 01:07 PM

You're going to have to store the million digits somewhere, so I suppose the answer is no, there isn't.

somebody plz help me to get

subh.singh007 @ 28 Dec 2010 05:40 PM

somebody plz help me to get rid of runtime error!!!!!!!!!!

#include<stdio.h>
#include<string.h>
int main ()
{
char a[50][50];
int i=0,flg=1,j,m,l,t,k;
scanf("%d",&t);
getchar();

while(t>i)
{
flg=1;

for(j=0;(a[i][j]=getchar())!='n';j++);
a[i][j]='';

l=strlen(a[i]);

if(l%2==0)
m=(l/2)-1;
else
m=l/2;
//printf("l=%d m=%d",l,m);
for(j=0;j<=m;j++)
{


a[i][m-j]=(((a[i][m-j]-48)+flg)%10)+48;
if(l%2!=0)
a[i][m+j]=a[i][m-j];
else
a[i][m+j+1]=a[i][m-j];


if(a[i][m-j]==48)
flg=1;
else
flg=0;  
}
if(flg==1)
{
for(k=l;k>0;k--)
a[i][k+1]=a[i][k];
a[i][0]='1';
a[i][l]='1';
//a[i][l+1]='';
}

i++;

}
for(i=0;i<t;i++)
printf("%sn",a[i]);
return 0;

Have you tested your code on

triplem @ 29 Dec 2010 02:12 AM

Have you tested your code on an input with a million digits?

First of all thanks to

sanjaynambiar @ 12 Jan 2011 03:42 PM

First of all thanks to Stephen for your response :) and very sorry for such a late reply for that.

This comment is a reply to your post Stephen Merriman - 1st Nov,2010 02:42:00.

I understand that accepted solutions may fail for some particular test cases which the judge

fails to check. But the test cases i checked included the sample input given in the problem statement.

And as I reported earlier, two different accepted code produced different answers. One of the code was

generatingsome strange output for the sample input 808, while other one was generating the output

8008 for 808, when it is clearly mentioned 818.

please check. Thanks :)

And there was a post by

sanjaynambiar @ 12 Jan 2011 03:46 PM

And there was a post by nikhil (nikhil - 17th Nov,2010 02:00:16.) saying my accepted solution was wrong :) actually what happened is that, I was getting all wrong answers and so I just tried submitting an accepted solution, which generated incorrect outputs as I've mentioned above.

Codechef is a head ache now

tauquir @ 13 Jan 2011 07:17 PM

Codechef is a head ache now as I think. When ever i post a solution it comes with some error. I quit codechef for some day say, month then again if i try , no luck. So, I decided to check some one else answer. As I wrote the code in python and I found someone answer in python posted for this question , (http://www.codechef.com/viewsolution/99312 ). I compile it and get shocked. for 1 -> 11 is the next palindrome but for 2 -> 22 is the palindome next to it. Can any one tell me why? Because this is a correct answer. So, I need to check whether I am wrong or code chef is wrong. Because from my point of view 1->11, 2->11, 3->11 ??????

Neither is correct. The first

triplem @ 14 Jan 2011 01:57 AM

Neither is correct. The first palindrome after 1 is 2. If an accepted solution fails on a certain case, then that case can't be part of the judge's tests.

@Stephen: Could you please

sachindraac @ 31 Jan 2011 11:32 PM

@Stephen: Could you please help me figure out the test case for which my code is producing the wrong answer. My code is here : http://www.codechef.com/viewsolution/440475

 

Thanks in advance,

Shachindra A C

the codechef has became a

ritesh_gupta @ 2 Feb 2011 12:21 PM

the codechef has became a headache....dont know what wong

with it

/////////////using c++//////////////////////

 

#include<iostream>
using namespace std;
int reverseNumber(int number)
{
int reversedNumber = 0;
while(number != 0)
{
reversedNumber = (reversedNumber * 10) + (number % 10);
number /= 10;
}
return reversedNumber;
}

int main()
{
int t;
int n;
int p;

int counter=0;


cin>>t;
int a[t];
do
{
cin>>n;       


p=reverseNumber(n);
if(n==p && n<=1000000)
{

a[counter]=p;
++counter;
}
else
{
for(int i=0;i<=1000000;i++)
{
n++;
p=reverseNumber(n);

if(n==p && n<=1000000)
{
a[counter]=p;
++counter;
break;
}

}

}   

t=t-1;

}
while(t!=0);
for(int i=0;i<=counter-1;i++)
{
cout<<a[i]<<endl;
}
system("pause");


}


RESUlT:WRONG ANSWER   

I tried the same code with java :it geves RUNTIME ERROR

//////////////java///////////////////

import java .util.Scanner;
public class Main
{
int reverseNumber(int number)
{
int reversedNumber = 0;
while(number != 0)
{
reversedNumber = (reversedNumber * 10) + (number % 10);
number /= 10;
}
return reversedNumber;
}


public static void main(String[] args) {
// TODO code application logic here
Main m=new Main();
m.go();
}
public  void go()
{
Scanner scanner=new Scanner(System.in);
int t;
int n;
int palin;

t=scanner.nextInt();
do
{
n=scanner.nextInt();
palin=reverseNumber(n);
if(n==palin && n<=1000000)
{
System.out.println(palin);
}
else
{
for(int i=0;i<1000;i++)
{
n++;

palin=reverseNumber(n);

if(n==palin && n<=1000000)
{
System.out.println(palin);
break;
}

}

}

t=t-1;
}
while(t!=0);

}

}

You should start by reading

triplem @ 2 Feb 2011 01:04 PM

You should start by reading the problem statement again. Did you read how large the input can be?

#!/usr/bin/perlmy $num =

lalita @ 18 Feb 2011 05:55 PM

#!/usr/bin/perl


my $num = $ARGV[0];
START:
my $num_pal = reverse($num);
my $count;
if ( $num == $num_pal)
{
print "the palindrome is $num n";
$num = $num+1;
$count++;
if ( $count == 2) {
exit;
}
else {
goto START;
}
}
else {
$num = $num + 1 ;
goto START;
}

Hello Admin, I have been

arovitn @ 22 Feb 2011 02:52 PM

Hello Admin,

I have been getting the same runtime error(NZEC) for my code in python.Its running perfectly fine on my system with python2.5 and python 2.7.I have tried several times.Please check the code - 465889 and let me know the details.I have also cross checked 1 million testcases of max possible sizes with the accepted code.It's working fine.Help me please

@admin Please help i am

vivsapru @ 24 Feb 2011 04:28 AM

@admin

Please help i am getting an output as "Wrong Answer" while submission , but the code works fine on my system:

Have checked for the following

cases I/P <9

where I/P like 999 0r 99 0r Increase in digit

and others please help last submmsion @vivsapru

Thanks in advance

@Admin Hello Please check my

vivsapru @ 5 Mar 2011 12:28 AM

@Admin

Hello Please check my solution it works correctly on my system ..... Plx pass me the test case fpr which it is failing

Giving runtime error, though

viditochani @ 21 Apr 2011 10:22 PM

Giving runtime error, though its working fine on my end...

 

#include<iostream>
using namespace std;
int palnext(char *);
int main()
{
char input[1000000];
int n;
cin>>n;
while(n!=0)
{
cin>>input;
palnext(input);
n--;
cout<<input<<"n";
}
cin.get();
cin.get();
return 0;
}
int palnext(char* a)
{
int half,temp,j=0,i=0;
while(a[i]!='')
i++;
half=i/2;
int flag=1,flag2=1;
temp=i-1;
while(j<half)
{
flag=1;
while(a[j]>a[temp])
{    
flag2=0;
a[temp]++;
}
while(a[j]<a[temp])
{
if(flag)
{
a[temp-1]++;
flag=0;
}
flag2=0;
a[temp]--;
}
j++;
temp--;
}
if(flag2)
{
if(i%2==0)
{
a[half-1]++;
a[half]++;
}
else
a[half]++;
}
return 0;
}

Hi, if someone willing to

sak3t @ 6 May 2011 03:18 PM

Hi,

if someone willing to help please look at solution id 541427

http://www.codechef.com/viewsolution/541427

considered all possible cases which came to mind.....still missing something i guess bcoz geting wrong answer

Hi, I have considered all the

kapilagarwal @ 14 May 2011 08:21 PM

Hi,

I have considered all the cases(I hope so), but it still gives the wrog answer. My solution id is 548588.

I hope there is not a problem in displaying the output.

import java.util.Scanner;/**

vgvineet4 @ 15 May 2011 11:48 AM

import java.util.Scanner;

/**
*
* @author roger
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args)  {
// TODO code application logic here
boolean flag=true;int x=0;
Scanner s=new Scanner(System.in);
int a=s.nextInt();
while(a>0)
{
String str=s.next();
int i=0;
x=Integer.parseInt(str);
x=x+1;
str=Integer.toString(x);

while(i<str.length())
{
while (flag)
{if(str.charAt(i)==str.charAt(str.length()-1-i))
{i++;
flag=false;
}
else
{
x=x+1;
str=Integer.toString(x);
}

}
flag=true;
}

System.out.println(str);
a--;

}
}
}
the code above is running good in my system but giving NZEC ERROR

PLEASE tell mem what's wrong with this code ASAP.

what should be the output for

quakerr90 @ 28 May 2011 02:18 PM
what should be the output for 0011111

hey admin, my code works fine

quakerr90 @ 1 Jun 2011 10:50 PM
hey admin, my code works fine when chkd with upto 100000 digits....can u pls tell me where i am going wrong???? also pls tell me the answer for my previus query as well

Anyone has any idea why this

sushantrocks @ 9 Jun 2011 02:10 PM
Anyone has any idea why this is tagged as wrong answer... have tried many times with all possible inputs but... http://www.codechef.com/viewsolution/569083

I'm having runtime errors for

jp_mastermind @ 17 Jun 2011 11:57 PM
I'm having runtime errors for my codes :-S would somebody mind checking for an error..? At first i thought it's because there was because of the spaces between the input and output, but still runtime error... It's working fine on my machine, why doesn't it work here? Please help import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); String ans=""; for(int j=0; j

sry i'm not sure i pasted it

jp_mastermind @ 18 Jun 2011 12:05 AM
sry i'm not sure i pasted it properly.. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); String ans=""; for(int j=0; j

@jp_mastermind post a link to

balajiganapath @ 18 Jun 2011 08:05 AM
@jp_mastermind post a link to your code instead of trying to post the whole code.

@admin-tell me the case for

sahebrm @ 3 Jul 2011 08:53 PM
@admin-tell me the case for which my code gives wrong answer http://www.codechef.com/viewsolution/590059

@admin There is some

jackiesteed @ 9 Jul 2011 02:39 PM
@admin There is some ambiguous blank line in the sample output, may you erase it.THX!

please look at the code

amitrishi13 @ 24 Aug 2011 03:07 PM
please look at the code here......it is showing time limit exceeded.. #include #include #include #include void get_pald(char *); int check_pald(char *); char str[1000001]; int main() { clock_t start, end; double runTime; int i,j; char str[1000001]; start = clock(); scanf("%d",&i); for(j=0;j=0;i--) { if((s[i] == '9') && (i==strlength-1)) { s[i] = '0'; carry = 1; } else if((s[i] == '9') && (carry == 1)) { s[i] = '0'; carry = 1; } else { if(carry == 1) s[i]++; if(i == strlength-1) s[i]++; carry = 0; } if((i == 0) && (carry == 1)) { //printf("hi i am here1n"); strlength = strlength + 1; s[i] = '1'; for(k = 1;k

#include #include #include

amitrishi13 @ 24 Aug 2011 03:10 PM
#include #include #include #include void get_pald(char *); int check_pald(char *); char str[1000001]; int main() { clock_t start, end; double runTime; int i,j; char str[1000001]; start = clock(); scanf("%d",&i); for(j=0;j=0;i--) { if((s[i] == '9') && (i==strlength-1)) { s[i] = '0'; carry = 1; } else if((s[i] == '9') && (carry == 1)) { s[i] = '0'; carry = 1; } else { if(carry == 1) s[i]++; if(i == strlength-1) s[i]++; carry = 0; } if((i == 0) && (carry == 1)) { //printf("hi i am here1n"); strlength = strlength + 1; s[i] = '1'; for(k = 1;k

the problem is given as "time

jastiger @ 27 Aug 2011 10:04 AM
the problem is given as "time exceeded" but when i test it on myself no such problem is there .. PLEASE HELP !!!

@admin could you please check

gogtesuyash @ 29 Aug 2011 01:27 AM
@admin could you please check my code and give me hint regarding whats going wrong ...waiting for your reply ,thanks

i am getting runtime error

amy_vivacious @ 31 Aug 2011 10:32 PM
i am getting runtime error again and again ....pls sm1 check #include #include int main() { int loop_enter,t,flag_1,flag,*a; char s[1000001]; long int c1,i,j,temp_i,temp_j; scanf("%d",&t); while(t--) { loop_enter=0; flag=0; flag_1=0; scanf("%s",s); c1=strlen(s)-1; a=(int *)malloc(c1*sizeof(int)); for(i=0;i<=c1;i++) a[i]=s[i]-48; a[c1]++; if(c1%2) { i=c1/2; j=i+1; } else { i=(c1/2)-1; j=(c1/2)+1; } temp_i=i; temp_j=j; while(i>0) { loop_enter=1; if(flag==1) a[j]=a[i]; else { if(a[i]>a[j]) { flag=1; a[j]=a[i]; } else if(a[i]9) { a[temp_i]=0; a[temp_j]=0; } else { //if(c1%2==0) //a[c1/2]=1; break; } temp_i--; temp_j++; } if(temp_i>=0) a[c1]=a[0]; else a[++c1]=1; } for(i=0;i<=c1;i++) printf("%d",a[i]); free(a); //free(s); printf("n"); } //getch(); return 0; }

there it is written "Numbers

lol2012 @ 1 Sep 2011 01:40 AM
there it is written "Numbers are always displayed without leading zeros." but every top 10 submit problems shows leading and trailing zeros in their solution .......admin ......plz correct this question .......it is misleading and makes confusion . also let our confidence down when we see such problems...

getting wrong ans......i have

amy_vivacious @ 1 Sep 2011 02:15 AM
getting wrong ans......i have tried number of test cases and it works fine...pls tell me the test case for which the program is showing wrong ans..thnx in advance My submission id is 640828

@admin: can you pls tell me

teerarajkumar @ 3 Sep 2011 03:20 AM
@admin: can you pls tell me the test cases where i am getting wrong output.. my code seems to work fine with whatever input i try with... reply as soon as possible..thanks in advance...

@admin can u pls reply

teerarajkumar @ 4 Sep 2011 01:47 AM
@admin can u pls reply quickly?

I read various comments

imdeepakg @ 15 Sep 2011 12:30 AM
I read various comments mentioning accepted solutions giving wrong answer. But I did not believe it. Then I decided to give a try to an accepted solution[http://www.codechef.com/viewsolution/186553]. I was really shocked to see it giving wrong answer. (1 gives answer 11) Surely judge can't test all cases but cases should be made in such a way that all scenarios are tested. Was it worth spending time for this problem at codechef!

Can some one tell me why my

harshas1989 @ 17 Sep 2011 12:54 PM
Can some one tell me why my solution is wrong. I tested for many cases. Its working fine. Admin can you give test cases on which you have evaluated my program.?

Hey I am getting runtime

chandransuraj @ 4 Nov 2011 12:58 AM
Hey I am getting runtime error for my solution: http://www.codechef.com/viewsolution/723048 I tested it for 100000 digit numbers. "Works only on my machine(R)" :(. Any suggestions. Thanks.

http://www.codechef.com/views

guidedmissile @ 12 Nov 2011 12:09 AM
http://www.codechef.com/viewsolution/731801 admin save me !!!!!!!!!!!!!!!!!! run time errors are like killing me !!!!!!!! plz for god sake help me !!!!!!!!!!

@guidedmissile: i did'nt try

monikadaryani @ 13 Nov 2011 01:07 PM
@guidedmissile: i did'nt try ur problem. but try "return 0;" instead of "return 1;" Use return 0; always..

Why am i getting runtime

monikadaryani @ 13 Nov 2011 11:24 PM
Why am i getting runtime error?? It works fine with my machine. Nor m i using a lot of space. i suppose there are QUITE A NUMBER OF PEOPLE WITH SAME ERROR. Admin please answer what could be the possible mistake.. my submission is http://www.codechef.com/viewsolution/732596

Can somebody help me out with

amitbhandarkar @ 18 Nov 2011 10:17 PM
Can somebody help me out with my code? It says wrong answer when i submit my program 1.#include 2.int main() 3.{ 4.int t,i,j; 5.scanf("%d",&t); 6.int input[t],output[t]; 7.for(i=0;i

help me out why do i get

amitbhandarkar @ 18 Nov 2011 10:32 PM
help me out why do i get wrong answer #include int fact(int ); int main() { int cases,i,input; scanf("%d",&cases); int value[cases]; for(i=0;i int main() { int t,i,j; scanf("%d",&t); int input[t],output[t]; for(i=0;i

Why am I getting runtime

rbkr @ 4 Jan 2012 08:28 AM
Why am I getting runtime error with this Java code? it's running fine on my machine: http://www.codechef.com/viewsolution/778588 Thanks.

I tested the code here too:

rbkr @ 4 Jan 2012 08:31 AM
I tested the code here too: https://ideone.com/PUmhi

i cant find out the error in

deba_22 @ 10 Jan 2012 09:42 PM
i cant find out the error in my answer in my last two submissions..

@admin please help.... wen

tbhatia @ 16 Jan 2012 11:53 PM
@admin please help.... wen im running my progrtam on my conputer, it is running without any errors.. but here it is giving a runtime error....please help.. programming language java import java.io.*; class palin { public int calc(int x) { int i,digit,sum=0,temp; for(i=x;i<100000;i++) { temp=i; sum=0; while(temp>=1) { digit=temp%10; sum=sum*10+digit; temp=temp/10; } if(sum==i) { break; } } return(sum); }// fuction calc ends public static void main(String args[])throws IOException { //int value=0; palin ob=new palin(); System.out.println("input"); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int num=Integer.parseInt(in.readLine()); int value[]=new int[num]; int i=0; while(i

Calling sprintf results in

tru3liar @ 31 Jan 2012 11:19 PM
Calling sprintf results in SIGSEGV? If yes, then how to fix it?

i used a suitable header file

chaubey12 @ 17 Feb 2012 10:13 PM
i used a suitable header file for itoa() .still i'm getting compilation error.some one please help

Just a heads up... flipping a

tribal @ 25 Mar 2012 12:54 AM
Just a heads up... flipping a string recursively here is a bad idea.. when you get close to 1000000 length string you kinda make the computer mad... Exception in thread "main" java.lang.StackOverflowError omnomnomnom lol..

hey could anybody tell me the

khushalbokadey @ 28 Mar 2012 02:41 AM
hey could anybody tell me the problem in my solution??? I am constantly getting wrong answer. http://www.codechef.com/viewsolution/931527

@stephen.i have exhausted all

floydfan @ 29 Mar 2012 03:03 AM
@stephen.i have exhausted all the possible inputs and my code is giving the right answer can u please give me a case where it give wrong answer.my solution id is 932204

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com