logo AlgoBeat OnlineJudge
登录 注册

#213156. [GCJ 2021 #3] Build-A-Pair

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 . Two of the valid pairs you can build are and . The following pairs, on the other hand, are not valid:

  • : has a leading zero.
  • : has a non-positive integer.
  • and : 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, . lines follow. Each line describes a test case with a single string of digits . Each character of is a digit you must use.

输出格式

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

样例

样例输入 1

4
1234
0011
07080
0899

样例输出 1

Case #1: 7
Case #2: 0
Case #3: 620
Case #4: 1

数据范围与提示

Sample Explanation

The optimal pair of integers to build are and for Sample Case #1, and for Sample Case #2, and for Sample Case #3, and and for Sample Case #4.

Limits

  • .
  • Each character of is a decimal digit.
  • At least two characters of are not .

Test Set 1 (3 Pts, Visible Verdict)

  • the length of .

Test Set 2 (12 Pts, Visible Verdict)

  • the length of .