Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Add a number which in form of String  RSS feed

 
krishna kumar.s
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a competitive programming problem I need to get a number which has 100000 digit as input and find next palindrome , I have coded half of the logic, for another half I need to add one(1) to the half portion of 500 digit string . I used some logic and it did not work out , if I use biginteger "TLE" error occurs. So please let me know a logic. To add just one to a String and get the result.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37222
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
krishna kumar.s wrote:For a competitive programming problem

This implies you should be writing the code yourself. What do you have so far with BigInteger? If you are allowed to show code, show a self contained example that illustrates the error.

There's probably some shortcuts to brute force since this is a competition. Maybe looking for patterns so you don't have to keep adding 1 at a time.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
krishna kumar.s wrote:I used some logic and it did not work out , if I use biginteger "TLE" error occurs. So please let me know a logic...

I'm afraid that's not how it works here. Why don't you show us what you've tried and precisely what errors you're getting (I have no idea what a 'TLE' error is) - cut and paste the stacktrace if you need to.

My suspicion is that you might not need BigInteger though, since the entire process (including "incrementing") can probably be done with the String - or maybe even better, a char[].
Hint: chars in Java are numeric.

Interesting little problem though.

Winston
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's TLE?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!