2 / 2
Sep 2008

#include<iostream> 
#include<sstream>
#include<string>
using namespace std;
int main(void) 
{
long int x,p=0;
cin>>x;
for(int i=0;i<x;i++){
long int n; 
long int m;
cin>>m;
m++;
string a; 
ostringstream ss;
ss << m;
a = ss.str();
while(true){
int licz=0,temp=0;    
bool t=true;
for(int k=a.size(),j=-1;k>=0;k--,j++){
        if(a[k]==' '){
                   k-=1;
                   temp--;
                   }
        if(a[j]==' '){
                   j+=1;
                   temp--;
                   }
        if(a[k]==a[j] || a[k]=='\0')licz+=1;
        else t = false;
        if(k==j)break;
        }
if(t==true){
            istringstream iss(a);
            iss >> n;
            cout<<n; 
            break;
            }
else {  
     istringstream iss(a);
     iss >> n;   
     n++;   
     ostringstream ss;
     ss << n;
     a = ss.str();
     } 
}//while
}//for
//getchar();
//return 0;  
}

...why wrong answer ?

  • created

    Sep '08
  • last reply

    Sep '08
  • 1

    reply

  • 99

    views

  • 2

    users

The input data can have up to a million digits. When it overflows int, your program encounters problems. You need to figure out how to solve the problem by working with strings.

And, besides that, the program doesn't print a newline after each case.

If you have questions about how to solve or debug a particular problem, you should post in the ProblemSet Archive section of the forum. This forum is for language-specific discussion.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 37 29d

Want to read more? Browse other topics in C and C++ or view latest topics.