当前位置:网站首页>1023 Have Fun with Numbers
1023 Have Fun with Numbers
2022-06-27 17:53:00 【Brosto_Cloud】
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!
Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.
Input Specification:
Each input contains one test case. Each case contains one positive integer with no more than 20 digits.
Output Specification:
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.
Sample Input:
1234567899
Sample Output:
Yes
2469135798高精加法:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int cnt1[10], cnt2[10];
int main() {
string s, s1 = "";
cin >> s;
for (int i = s.size() - 1; i >= 0; i--) {
cnt1[s[i] - '0']++;
}
s = '0' + s;
s1 = s;
for (int i = s.size() - 1; i >= 1; i--) {
int x = s[i] - '0' + s1[i] - '0';
s1[i] = '0' + x % 10;
s1[i - 1] += x / 10;
}
if (s1[0] != '0') {
cout << "No" << endl;
cout << s1;
} else {
for (int i = 1; i < s1.size(); i++) {
cnt2[s1[i] - '0']++;
}
bool flag = 1;
for (int i = 0; i < 10; i++) {
if (cnt1[i] != cnt2[i]) {
flag = 0;
break;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
for (int i = 1; i < s1.size(); i++) {
cout << s1[i];
}
}
return 0;
}
边栏推荐
- Is Guosen Securities a state-owned enterprise? Is it safe to open an account with Guosen Securities?
- 数仓的字符截取三胞胎:substrb、substr、substring
- Cdga | what is the core of digital transformation in the transportation industry?
- openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
- Character interception triplets of data warehouse: substrb, substr, substring
- How to encapsulate and call a library
- Market status and development prospect forecast of the global shuttleless air jet loom industry in 2022
- 《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
- NVIDIA Clara-AGX-Developer-Kit installation
- 429-二叉树(108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树、 106.从中序与后序遍历序列构造二叉树、235. 二叉搜索树的最近公共祖先)
猜你喜欢

在线文本按行批量反转工具

OpenSSL client programming: SSL session failure caused by an obscure function

Bit. Store: long bear market, stable stacking products may become the main theme

Comprehensively analyze the zero knowledge proof: resolve the expansion problem and redefine "privacy security"

Oracle 获取月初、月末时间,获取上一月月初、月末时间

深度学习和神经网络的介绍

基于STM32F103ZET6库函数按键输入实验

Error reported by Huada MCU Keil_ Weak's solution

2022年第一季度消费金融APP用户洞察——总数达4479万人

基于STM32F103ZET6库函数蜂鸣器实验
随机推荐
OpenSSL client programming: SSL session failure caused by an obscure function
作为软件工程师,给年轻时的自己的建议(下)
基础数据类型和复杂数据类型
信息学奥赛一本通 1335:【例2-4】连通块
金鱼哥RHCA回忆录:DO447管理项目和开展作业--创建作业模板并启动作业
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
运算符的基础知识
Labelimg usage guide
Market status and development prospect of resorcinol derivatives for skin products in the world in 2022
Core dynamic Lianke rushes to the scientific innovation board: with an annual revenue of 170million yuan, Beifang Electronics Institute and Zhongcheng venture capital are shareholders
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
中金证券经理给的开户二维码安全吗?找谁可以开户啊?
流程判断-三目运算-for循环
谈谈线程安全
Market status and development prospect forecast of the global infusion needle less connector industry in 2022
Where to look at high-yield bank financial products?
【登录界面】
CMS 执行的七个阶段
PCB线路板蛇形布线要注意哪些问题?
教你打印自己的日志 -- 如何自定义 log4j2 各组件