首页 > Code > wild number

wild number

2007年8月14日 timmy 发表评论 阅读评论 703 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大的数。

若日志经rss订阅或导入到外站,可能有些视频和图片无法显示,请点击原文链接查看。
本文链接地址: http://imtimmy.com/wildnumber/

转载请注明: 转载自Timmy's Blog

如果你觉得本博内容不错,欢迎 [订阅 Timmy's Blog],以便第一时间了解本博更新内容;


不妨再看看这些相关的日志:

  1. calculating the taxi fares
  2. Do you still love me? Maybe.
  3. 实验十三  排序算法的应用
  4. 统计文件中字符
  5. 统计字符

分类: Code 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :cool: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O