Codeforces Round #742 (Div. 2) C. Carrying Conundrum

题目:

C. Carrying Conundrum
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 would be as shown:

在这里插入图片描述

However, Alice evaluates it as shown:
在这里插入图片描述

In particular, this is what she does:

add 9 and 6 to make 15, and carry the 1 to the column two columns to the left, i. e. to the column “0 9”;
add 3 and 7 to make 10 and carry the 1 to the column two columns to the left, i. e. to the column “2 2”;
add 1, 0, and 9 to make 10 and carry the 1 to the column two columns to the left, i. e. to the column above the plus sign;
add 1, 2 and 2 to make 5;
add 1 to make 1.
Thus, she ends up with the incorrect result of 15005.
Alice comes up to Bob and says that she has added two numbers to get a result of 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. Note that pairs (a,b) and (b,a) are considered different if a≠b.

Input

The input consists of multiple test cases. The first line contains an integer 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≤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.

Example

input

5
100
12
8
2021
10000

output

9
4
7
44
99

解析

会发现,奇数位只会进位到奇数位,偶数位只会进位到偶数位。即:相邻的奇数位之间满足十进制关系(偶数位同理)
例:12的奇数位为2,偶数位为1;
2可以由0+2 1+1 2+0获得
1可以由0+1 1+0获得
2*3即为总的方案数,最后需要减去奇偶数位和全为0的情况

AC代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
using namespace std;

int main()
{
    int t;
    cin >> t;
    int a;
    while (t--)
    {
        cin>>a;
        int temp=a;
        int num=1;//位数
        while(temp/10!=0)
        {
            num++;
            temp/=10;
        }
        num++;
        int ji=0,ou=0;
        int num1=1,num2=1;
        for(int i=1;i<=num;i++)
        {
            if(i%2==0)//偶数位
            {
                ou+=a%10*num1;
                num1*=10;
            }
            else//奇数位
            {
                ji+=a%10*num2;
                num2*=10;
            }
            a/=10;
        }
        ji++,ou++;
        cout<<ji*ou-2<<endl;
    }
    return 0;
}
  • 新手小白,如有问题望斧正!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值