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
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September Cook-off » Digit Rotation

Digit Rotation

Problem code: DIGROT

  • All Submissions

All submissions for this problem are available.

For any positive integer, we define a digit rotation as either moving the first digit to the end of the number (left digit rotation), or the last digit to the front of the number (right digit rotation). For example, the number 12345 could be left digit rotated to 23451, or right digit rotated to 51234. If there are any leading zeros after digit rotation, they must be removed. So 10203 could be left digit rotated to 2031, then left digit rotated again to 312. Given an integer N, determine the largest integer that can result from performing a series of one or more digit rotations on N.

Input

Input will begin with an integer T (at most 1000), the number of test cases. Each test case consists of a positive integer N<100000000 (10^8) on a line by itself.

Output

For each test case, print the largest integer that can result from performing one or more digit rotations on N.

Sample Input

6
12345
54321
10901
211011
7
90

Sample Output

51234
54321
11090
211011
7
9

Author: pieguy
Date Added: 2-09-2011
Time Limit: 2 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, PERL6, 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.

why input 90 has output 9

rmahor @ 18 Sep 2011 09:37 PM
why input 90 has output 9

@rmahor: at least one digit

david_adm @ 18 Sep 2011 09:42 PM
@rmahor: at least one digit rotation must be performed

in case of 211011 no rotation

nehalodha73 @ 18 Sep 2011 10:01 PM
in case of 211011 no rotation is performed?

@nehalodha73: There is a way

david_adm @ 18 Sep 2011 10:09 PM
@nehalodha73: There is a way to transform 211011 to 211011 using at least one digit rotation. It is up to you to determine how.

can the number begin with a

prerak92 @ 18 Sep 2011 10:27 PM
can the number begin with a leading zero??

@prerak92: numbers cannot

david_adm @ 18 Sep 2011 10:29 PM
@prerak92: numbers cannot have leading zeros.

why isn't 10901 rotated to

deadlydecoder @ 18 Sep 2011 10:43 PM
why isn't 10901 rotated to give 90110?

@deadlydecoder:only one digit

david_adm @ 18 Sep 2011 10:47 PM
@deadlydecoder:only one digit may be moved at a time, and leading zeros must be removed after each rotation.

Is a newline at the end of

anvitsingh @ 18 Sep 2011 11:09 PM
Is a newline at the end of last output allowed / required ? My code runs correctly on a host of test cases, but CodeChef gives Wrong Answer :(

@anvitsingh: differences in

david_adm @ 18 Sep 2011 11:17 PM
@anvitsingh: differences in whitespace are ignored by the judge.

can a right rotation follow a

apti_tude @ 18 Sep 2011 11:18 PM
can a right rotation follow a left rotation and vice versa ?

@apti_tude: Yes.

david_adm @ 18 Sep 2011 11:23 PM
@apti_tude: Yes.

guys why i cant see any

aayushjatrana @ 20 Sep 2011 03:30 PM
guys why i cant see any submit ... button

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef 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