IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> codeforces 1567 C. Carrying Conundrum -> 正文阅读

[游戏开发]codeforces 1567 C. Carrying Conundrum

本场比赛其他题目的题解

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?(1t1000) — 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?(2n109) — 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;
}
  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2021-09-14 13:41:42  更:2021-09-14 13:42:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 17:18:18-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码