The Next PalindromeProblem code: PALIN |
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 |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

Can anyone tell me what is wrong with my output in the last submission. It works fine for hte sample output on my machine
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
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
does single digit number is
1: I believe the test input
hey this code giving out put
hey this code giving out put in my compiler
better check it suggest me if any mistakes
@ADMIN my code is workin fine
@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
@ravi
The input can have numbers up to (and including) 1000000 digits; 400 digits is too little.
i think the longest number
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
i m some problem in
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
No, 00100 has leading zeroes and is not a number.
my code working fine in my
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
Please take a look at www.codechef.com/help for a sample solution in c or c++.
are there extra spaces in the
There won't be any extra
i m generating the next
i checked for my 1000000 and
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
It says the number can be 1000000 digits long, not just 1000000 which is only 7 digits long.
i am not able to understand
can anyone plz tell me wts
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
Please read the FAQ and the Sample Solutions
@admin wats the limit for
@admin
wats the limit for test cases ?
9 seconds
9 seconds
actually i talkin about max
actually i talkin about max value for first line of input.
10
10
@admin, max value for first
@admin,
max value for first line of input is not specified in the problem..
thank u.
thank u.
@admin, i submitted solution
@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
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
@admin,
thank you,finally i got where i m wrong.
public class Demo { public
admin, can you tell me what
admin,
can you tell me what is the complation error my submission is giving. It compiles fine on VC++
You have submitted a blank
You have submitted a blank file. That is the reason why it is giving a compile error.
i have written my program in
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.
Read the FAQ.
@admin can u tell me for what
@admin
can u tell me for what input am i getting wrong answer???
soln id : [120718]
no problem...got it...
no problem...got it...
@admin. I tried my code on
@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
@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
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
Got it admin.
Minor bug. I am happy now. Thanks anyway.
i am getting a wrong answer
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
@ 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
how can a input of 1000000 digits can be taken in language c
can anyone help?????????
A char array?
A char array?
bt can an array be declared
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
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
Declare it outside your function, as a global entity.
i think my code is correct
i think my code is correct ... why it is showing Wrong Answer please help
It is showing Wrong Answer
It is showing Wrong Answer because it is not correct, so you shouldn't think it is :P
someone please send me some
someone please send me some test cases id: dalchand@iitkgp.ac.in ... with answer :)
@stephen no it is correct...
@stephen no it is correct... :P
can someone tell me about the
can someone tell me about the input/output format... i'm new at codechef :(
I'm taking iput as: //MAX =
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
sorry ? mark is null character ' '
' \ 0 '
' 0 '
Please stop spamming. Your
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
@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
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
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
@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
The input / output format is mentioned in the problem statement. Please check it yourself.
@admin hii, i checked my code
@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
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
@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?
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
@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
@stephen :Thanks for ur help I got my mistake.
what is the range of t ??
what is the range of t ??
Getting a wrong answer for
Getting a wrong answer for the submission 185356.
Anyone willing to tell me why ?
@admin,@stephen,@Aniruddha ca
@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
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
sorry my mistake ... its million digits not million number ... extremely sorry
@admin, @stephen Any guesses
@admin, @stephen
Any guesses to what may be wrong with the submission 185356 ?
@stephen,@Aniruddha please
@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
@stephen,@Aniruddha
submission id is 187589
@stephen,@Aniruddha PLEASE
@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
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
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
#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
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
plz help me
i would love to read more
i would love to read more from you on this
Can anyone find the error in
Can anyone find the error in my program.............
http://www.codechef.com/viewsolution/231494
Somebody who has solved the
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
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
i'm getting correct answer according to following program but its not getting accepted here.
Can somebody find out d mistake in the following:
100000 digits means value or
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
It says digits; it means digits.
im getting a runtime (other)
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
@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
@Sarthak. well try out the cases like 99,999 etc.. and check what result u get for'em
I am keeping on getting wrong
I am keeping on getting wrong answer. Pl help my submission id is 274092
I resubmitted but still
I resubmitted but still gettin the wrong answer. Admin Pl help my submission code is 274109
@karthik Check your output
@karthik
Check your output for 9,191,1991,19991...
i am submitting the following
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
@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
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);
}
You didn't even read the
You didn't even read the comment directly above yours..
thanx.....4 reply.
thanx.....4 reply.
My solution is running fine
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.
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
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
Yes, that definitely won't
Yes, that definitely won't work, since new lines have an \r character in them (see the FAQ).
#include <iostream>#include
#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
Did you read how big K can be?
@Admin, when i submitted my
@Admin,
when i submitted my soln, i got internal error occured in the system error . when does that happen ?
My code is working perfectly
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
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
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
@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
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
@Stephen
i am declaring a character array f[1000000] so why is it not providing enough space????????help!!!!!
An array of length 1000000
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
sry for my blunder!!!!!!!!!!!!
still wrong answer plz
still wrong answer plz help!!!!!!
http://www.codechef.com/viewsolution/373888
plzzz help admin still i am
plzzz help admin still i am gettting a wrong answer...
http://www.codechef.com/viewsolution/374688
hello admin and
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
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
yeah really kicked myself!!!
thanks by the way.
wht abt my query my solution
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:
@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
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
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
*Q--> W -- Wrong
That's not the output that
That's not the output that program produces. You must be testing it incorrectly.
Sory for that compare the
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
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
Please don't post your code in the comments. Read the input constraints again.
I tested my code for all
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
http://www.codechef.com/viewsolution/392720 which test case is my code failing!! somebody help!!
It is easy to find test cases
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
@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
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
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
Did you not read how big K could be?
@Stephen..I converted all my
@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
Why would long help? I'll say it again, have you read how large K can be?
so is there anyway by which
so is there anyway by which this one can be solved without using a character array.
You're going to have to store
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
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
Have you tested your code on an input with a million digits?
First of all thanks to
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
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
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
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
@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
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
You should start by reading the problem statement again. Did you read how large the input can be?
#!/usr/bin/perlmy $num =
#!/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
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
@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
@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
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
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
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;/**
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
hey admin, my code works fine
Anyone has any idea why this
I'm having runtime errors for
sry i'm not sure i pasted it
@jp_mastermind post a link to
@admin-tell me the case for
@admin There is some
please look at the code
#include #include #include
the problem is given as "time
@admin could you please check
i am getting runtime error
there it is written "Numbers
getting wrong ans......i have
@admin: can you pls tell me
@admin can u pls reply
I read various comments
Can some one tell me why my
Hey I am getting runtime
http://www.codechef.com/views
@guidedmissile: i did'nt try
Why am i getting runtime
Can somebody help me out with
help me out why do i get
Why am I getting runtime
I tested the code here too:
i cant find out the error in
@admin please help.... wen
Calling sprintf results in
i used a suitable header file
Just a heads up... flipping a
hey could anybody tell me the
@stephen.i have exhausted all