Skip to content

Instantly share code, notes, and snippets.

@st0le
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save st0le/be15452ce5a9574a3c43 to your computer and use it in GitHub Desktop.

Select an option

Save st0le/be15452ce5a9574a3c43 to your computer and use it in GitHub Desktop.
Easy problem of FB Hacker Cup - 2015

#Cooking the Books

###15 points

Every business can make use of a good accountant and, if they're not big on following the law, sometimes a bad one. Bad accountants try to make more money for their employers by fudging numbers without getting caught.

Sometimes a bad accountant wants to make a number larger, and sometimes smaller. It is widely known that tax auditors will fail to notice two digits being swapped in any given number, but any discrepancy more egregious will certainly be caught. It's also painfully obvious when a number has fewer digits than it ought to, so a bad accountant will never swap the first digit of a number with a 0.

Given a number, how small or large can it be made without being found out?

###Input

Input begins with an integer T, the number of numbers that need tweaking. Each of the next T lines contains a integer N.

###Output

For the ith number, print a line containing "Case #i: " followed by the smallest and largest numbers that can be made from the original number N, using at most a single swap and following the rules above.

###Constraints

  • 1 ≤ T ≤ 100
  • 0 ≤ N ≤ 999999999
  • N will never begin with a leading 0 unless N = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment