c++Educational Codeforces Round 147 (Rated for Div. 2)A - Matching

文章提供了一个C++程序,用于计算给定整数模板匹配的正整数数量。程序基于组合方法,考虑模板中每个位置可能的数字值。如果模板首字符是0,则无匹配整数;如果是其他数字,则首位有1种选择;如果是问号,则首位可能有9种选择。对于后续位,每个问号代表10种可能性。程序遍历模板并计算所有可能的组合。
摘要由CSDN通过智能技术生成

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;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪子小院

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值