A. Matching
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output
An integer template is a string consisting of digits and/or question marks.
A positive (strictly greater than 00) integer matches the integer template if it is possible to replace every question mark in the template with a digit in such a way that we get the decimal representation of that integer without any leading zeroes.
For example:
- 4242 matches 4?;
- 13371337 matches ????;
- 13371337 matches 1?3?;
- 13371337 matches 1337;
- 33 does not match ??;
- 88 does not match ???8;
- 13371337 does not match 1?7.
You are given an integer template consisting of at most 55 characters. Calculate the number of positive (strictly greater than 00) integers that match it.
Input
The first line contains one integer t� (1≤t≤2⋅1041≤�≤2⋅104) — the number of test cases.
Each test case consists of one line containing the string s� (1≤|s|≤51≤|�|≤5) consisting of digits and/or question marks — the integer template for the corresponding test case.
Output
For each test case, print one integer — the number of positive (strictly greater than 00) integers that match the template.
Example
input
8
??
?
0
9
03
1??7
?5?
9??99
output
90
9
0
1
0
100
90
100
AC:(c++)
In a positive integer, the first digit is from 1
to 9
, and every next digit can be any. This allows us to implement the following combinatorial approach:
calculate the number of different values for the first digit, which is 0
if the first character of s
is 0, 1
if the first character of s
is any other digit, or 9
if the first character of s
is ?;
calculate the number of different values for each of the other digits, which is 1
if the corresponding character of s
is a digit, or 10
if it is ?;
multiply all these values.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
string s;
cin >> s;
int ans = 1;
if(s[0] == '0') ans = 0;
if(s[0] == '?') ans = 9;
for(int j = 1; j < s.size(); j++)
if(s[j] == '?')
ans *= 10;
cout << ans << endl;
}
}