Topic Links:
pku:http://poj.org/problem?id=3340
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=2410
Description
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 I N X is equal to the character in the same position in W (it means so can replace a question mark W ith any digit). For example, 365198 matches the wild number 36?1?8, but 360199, 361028, or 36128 does not. Write A program This reads a wild number W and a number X from input, both of length n, and Det Ermines the number of n-digit numbers that match W and is greater than x.
Input
There is multiple test cases in the input. Each test case consists of 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 characters. The last line of input contains a single character #.
Output
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?82364288?3910?5#
Sample Output
10004
Source
Tehran 2006
Test instructions
Give a string of two numbers, "?" in string one, and ask in '? ' Position fill number total of how many fill in the method, ensure that the string is greater than two!
The code is as follows:
#include <cstdio> #include <cstring> #include <cmath>const int maxn = 17;typedef __int64 ll;int cont; LL Ans;char S1[maxn];char S2[MAXN]; ll POW (ll N, ll K) { ll s = 1; for (LL i = 0; i < K; i++) { s*=n; } return s;} void solve (int len, int k) {for (int i = 0; i < len; i++) { if (s1[i] = = '? ') { ans+= (9-(s2[i]-' 0 ')) *pow (,--cont); } else if (S1[i] < s2[i]) return; else if (S1[i] > S2[i]) { ans+=pow (10,cont); return;}}} int main () {while (~scanf ("%s", S1)) { ans = 0; Cont = 0; if (s1[0] = = ' # ') break ; scanf ("%s", S2); int len = strlen (S1); for (int i = 0; i < len; i++) { if (s1[i] = = '? ') cont++; } Solve (len,0); printf ("%i64d\n", ans); } return 0;}
POJ 3340 & HDU 2410 Barbara Bennett ' s Wild Numbers (math)