本场比赛其他题目的题解
A. Domino Disaster
B. MEXor Mixup
C. Carrying Conundrum
D. Expression Evaluation Error
E. Non-Decreasing Dilemma
C. Carrying Conundrum
题目描述
Alice has just learned addition. However, she hasn’t learned the concept of “carrying” fully — instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum 2039 + 2976 2039 + 2976 2039+2976 would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
- add 9 9 9 and 6 6 6 to make 15 15 15, and carry the 1 1 1 to the column two columns to the left, i. e. to the column " 0 0 0 9 9 9";
- add 3 3 3 and 7 7 7 to make 10 10 10 and carry the 1 1 1 to the column two columns to the left, i. e. to the column " 2 2 2 2 2 2";
- add 1 1 1, 0 0 0, and 9 9 9 to make 10 10 10 and carry the 1 1 1 to the column two columns to the left, i. e. to the column above the plus sign;
- add 1 1 1, 2 2 2 and 2 2 2 to make 5 5 5;
- add 1 1 1 to make 1 1 1.
Thus, she ends up with the incorrect result of 15005 15005 15005.
Alice comes up to Bob and says that she has added two numbers to get a result of n n n. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of n n n. Note that pairs ( a , b ) (a, b) (a,b) and ( b , a ) (b, a) (b,a) are considered different if a ≠ b a \ne b a=b.
Input
The input consists of multiple test cases. The first line contains an integer t ( 1 ≤ t ≤ 1000 ) t\ (1\le t\le 1000) t (1≤t≤1000) — the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer n ( 2 ≤ n ≤ 1 0 9 ) n\ (2\le n\le 10^9) n (2≤n≤109) — the number Alice shows Bob.
Output
For each test case, output one integer — the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of n n n.
Example
Input1
5
100
12
8
2021
10000
Output1
9
4
7
44
99
Note
In the first test case, when Alice evaluates any of the sums 1 + 9 , 2 + 8 , 3 + 7 , 4 + 6 , 5 + 5 , 6 + 4 , 7 + 3 , 8 + 2 , o r 9 + 1 1+9, 2+8, 3+7, 4+6, 5+5, 6+4, 7+3, 8+2, or 9+1 1+9,2+8,3+7,4+6,5+5,6+4,7+3,8+2,or9+1, she will get a result of 100 100 100. The picture below shows how Alice evaluates 6 + 4 6+4 6+4:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5cx3hQfu-1631530468282)(https://espresso.codeforces.com/704366959d40aa707742d72e1e660c9027ff73cc.png)]
题意
多组样例,每次给你一个正整数 n n n。表示两个多位数相加的和。但是这个加法比较特殊,每次进位都是进到前两位上。(逢十进十?)
问你有多少加数被加数对,满足用上述加法得到的和为 n n n。
分析
我们先考虑正常加法,逢十进一的情况,如果一个和为 n n n,那么有多少种两个非负整数相加得到 n n n 呢?
很显然有的方案数为 0 + n , 1 + ( n − 1 ) , … , n + 0 0+n, 1+(n-1), \dots, n+0 0+n,1+(n−1),…,n+0 一共 n + 1 n+1 n+1 种。
基于此, 很自然的想法是,既然都是隔一位进一位,那么显然我可以按照奇数位,偶数位进行拆分,拆成两个和。
剩下的问题不就转换成了两个子问题,每个子问题都是 如果一个和为 n n n,呢么有多少种两个非负整数相加得到 n n n 呢?
最后一个点是,由于题目要求不能有一个加数为 0 0 0 所以需要排除 0 + n , n + 0 0+n, n+0 0+n,n+0 这两种case。
#include<bits/stdc++.h>
using namespace std;
void solve() {
string a;
cin>>a;
long long num[2] = {0,0};
for(int i = 0;i<a.length();i++) num[i&1] = num[i&1]*10 + a[i] - '0';
cout<<(num[0]+1)*(num[1]+1) - 2<<endl;
}
int main() {
int t;
cin>>t;
while(t--) solve();
return 0;
}