#P13193. [GCJ 2016 #1B] Close Match

[GCJ 2016 #1B] Close Match

题目描述

You are attending the most important game in sports history. The Oceania Coders are playing the Eurasia Jammers in the Centrifugal Bumble-Puppy world finals. Unfortunately, you were sleep deprived from all the anticipation, so you fell asleep during the game!

The scoreboard is currently displaying both scores, perhaps with one or more leading zeroes (because the scoreboard displays a fixed number of digits). While you were asleep, some of the lights on the scoreboard were damaged by strong ball hits, so one or more of the digits in one or both scores are not being displayed.

You think close games are more exciting, and you would like to imagine that the scores are as close as possible. Can you fill in all of the missing digits in a way that minimizes the absolute difference between the scores? If there is more than one way to attain the minimum absolute difference, choose the way that minimizes the Coders' score. If there is more than one way to attain the minimum absolute difference while also minimizing the Coders' score, choose the way that minimizes the Jammers' score.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} cases follow. Each case consists of one line with two non-empty strings C\mathbf{C} and J\mathbf{J} of the same length, composed only of decimal digits and question marks, representing the score as you see it for the Coders and the Jammers, respectively. There will be at least one question mark in each test case.

输出格式

For each test case, output one line containing Case #x: c j, where xx is the test case number (starting from 1), cc is C\mathbf{C} with the question marks replaced by digits, and jj is J\mathbf{J} with the question marks replaced by digits, such that the absolute difference between the integers represented by cc and jj is minimized. If there are multiple solutions with the same absolute difference, use the one in which cc is minimized; if there are multiple solutions with the same absolute difference and the same value of cc, use the one in which jj is minimized.

4
1? 2?
?2? ??3
? ?
?5 ?0
Case #1: 19 20
Case #2: 023 023
Case #3: 0 0
Case #4: 05 00

提示

Sample Explanation

In sample case #4, note that the answer cannot be 15 10; that minimizes the absolute difference, but does not minimize the Coders' score. Nor can the answer be 05 10; that minimizes the absolute difference and the Coders' score, but does not minimize the Jammers' score.

Limits

  • 1T2001 \leqslant \mathbf{T} \leqslant 200.
  • C\mathbf{C} and J\mathbf{J} have the same length.

Small dataset (Test Set 1 - Visible)

  • $1 \leqslant \text{the length of } \mathbf{C} \text{ and } \mathbf{J} \leqslant 3$.

Large dataset (Test Set 2 - Hidden)

  • $1 \leqslant \text{the length of } \mathbf{C} \text{ and } \mathbf{J} \leqslant 18$.