• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Add a number which in form of String

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's TLE?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic