首页 > Code > wild number

wild number

2007年8月14日 发表评论 阅读评论 767 views

A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and every non-question mark character in X is equal to the character in the same position in W (it means that you can replace a question mark with any digit). For example, 365198 matches the wild number 36?1?8, but 360199, 361028, or 36128 does not. Write a program that reads a wild number W and a number X from input, both of length n, and determines the number of n-digit numbers that match W and are greater than X.

There are multiple   cases in the input. Each test case consists of two lines of the same length. The first line contains a wild number W, and the second line contains an integer number X. The length of input lines is between 1 and 10 characters. The last line of input contains a single character #.

For each test case, write a single line containing the number of n-digit numbers matching W and greater than X (n is the length of W and X).

Sample Input

36?1?8
236428
8?3
910
?
5
#

Sample Output

100
0
4

一个wild number(这个不知道怎么翻)是一串包含数字和问号的字符串。一个数字X与一个wild number W有相同的长度,而且每一个非问号位上的字符都相同,那么这两个字符串相互匹配(就是说你可以将问号替换成任意的数字)。例如,365198与wild number字符串36?1?8相匹配,但是360199,361028和36128都不与此匹配。写一段程序,读入一串wild number字符和一个数字X,长度都为n,并求出这些与W匹配的n位数字中比X大的数字。

输入部分有多重检测条件。每一项检测条件由相同长度的两行组成。第一行包含一个wild number W,第二行包含一个整数X。输入的字符的长度为1到10字符。最后一行包含单一的一个字符#。

对于每一个检测项,输出一行,包含n位数字中与W相匹配并比X大的数。

分类: Code 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :cool: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O