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

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

Challenge Nine

면접 대비

메모리 제한1024 MB

요약
N에 숫자 하나를 정확히 한 번 끼워 넣어 9의 배수이면서 가장 작은 수를 만들되, 앞자리에 0이 오면 안 된다.
난이도

보통10점 중 5점

유형
그리디, 수학, 문자열
정답자
아직 제출이 없습니다

문제

Ada gives John a positive integer NN. She challenges him to construct a new number (without leading zeros), that is a multiple of 99, by inserting exactly one digit (0 …… 9) anywhere in the given number NN. It is guaranteed that NN does not have any leading zeros.

As John prefers smaller numbers, he wants to construct the smallest such number possible. Can you help John?

입력

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case has a single line containing a positive integer NN: the number Ada gives John.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the new number constructed by John. As mentioned earlier, yy cannot have leading zeros.

제한

  • 1≤T≤1001≤T≤100.

힌트

In Sample Case #1, there are only two numbers that can be constructed satisfying the divisibility constraint: 4545 and 5454. John chooses the smaller number.

In Sample Case #2, 333333 is the only number possible.

In Sample Case #3, there are four possible options - 212121212121, 122121122121, 121221121221 and 121212121212 - out of which the smallest number is 121212121212.

예제1

  1. 예제 1

    입력
    3
    5
    33
    12121
    
    예상 출력
    Case #1: 45
    Case #2: 333
    Case #3: 121212