当前位置:网站首页>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;
}
边栏推荐
- 作用域-Number和String的常用Api(方法)
- 可靠的分布式锁 RedLock 与 redisson 的实现
- 基于STM32F103ZET6库函数按键输入实验
- How to encapsulate and call a library
- Market status and development prospect forecast of the global infusion needle less connector industry in 2022
- 芯动联科冲刺科创板:年营收1.7亿 北方电子院与中城创投是股东
- 在线文本按行批量反转工具
- 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
- External interrupt experiment based on stm32f103zet6 library function
- 运算符的基础知识
猜你喜欢
随机推荐
Introduction to deep learning and neural networks
Where to look at high-yield bank financial products?
ABAP随笔-EXCEL-3-批量导入(突破标准函数的9999行)
Blink SQL内置函数大全
什么是SSR/SSG/ISR?如何在AWS上托管它们?
xctf攻防世界 MISC薪手进阶区
数仓的字符截取三胞胎:substrb、substr、substring
Code and principle of RANSAC
Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
External interrupt experiment based on stm32f103zet6 library function
One to one relationship
redis集群系列二
Market status and development prospect forecast of global active quality control air sampler industry in 2022
“我让这个世界更酷”2022华清远见研发产品发布会圆满成功
[cloud based co creation] the "solution" of Digital Travel construction in Colleges and Universities
让单测变得如此简单 -- spock 框架初体验
《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
Keras deep learning practice (12) -- facial feature point detection
Erreur Keil de Huada Single Chip Computer La solution de Weak
券商经理的开户二维码开户买股票安全吗?有谁知道啊









