아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Build-A-Pair

면접 대비

시간 제한5초메모리 제한1024 MB

요약
주어진 숫자들을 두 개의 양의 정수로 나누어 각각 앞자리에 0이 오지 않게 만들고, 두 정수의 차이의 최솟값을 구한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

You want to build a pair of positive integers. To do that, you are given a list of decimal digits to use. You must use every digit in the list exactly once, but you get to choose which ones to use for the first integer and which ones to use for the second integer. You also get to choose the order of the digits within each integer, except you cannot put a zero as the most significant (leftmost) digit in either integer. Note that you cannot choose just a zero for one integer either, because it would not be positive.

For example, you could be given the list [1,0,2,0,4,3]. Two of the valid pairs you can build are (200,143) and (3,12400). The following pairs, on the other hand, are not valid:

  • (0102,34): has a leading zero.
  • (0,12340): has a non-positive integer.
  • (10,243) and (12300,47): the list of digits in each of these pairs is not exactly equal to the given list of digits.

Given the list of digits to use, what is the minimum absolute difference between the two built integers that can be achieved?

입력

The first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with a single string of digits D. Each character of D is a digit you must use.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum possible absolute difference between the two integers built from D according to the rules above.

제한

  • 1 ≤ T ≤ 100.
  • Each character of D is a decimal digit.
  • At least two characters of D are not 0.

힌트

The optimal pair of integers to build are 31 and 24 for Sample Case #1, 10 and 10 for Sample Case #2, 700 and 80 for Sample Case #3, and 89 and 90 for Sample Case #4.

예제1

  1. 예제 1

    입력
    4
    1234
    0011
    07080
    0899
    
    예상 출력
    Case #1: 7
    Case #2: 0
    Case #3: 620
    Case #4: 1