当前位置:网站首页>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;
}
边栏推荐
- 让单测变得如此简单 -- spock 框架初体验
- 国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)
- 经纬度分析
- 现在网上买股票开户身份证信息安全吗?
- 信息学奥赛一本通 1335:【例2-4】连通块
- Comprehensively analyze the zero knowledge proof: resolve the expansion problem and redefine "privacy security"
- GIS遥感R语言学习看这里
- Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
- 高收益银行理财产品在哪里看?
- 一对一关系
猜你喜欢

Solution of adding st-link to Huada MCU Keil

Minmei new energy rushes to Shenzhen Stock Exchange: the annual accounts receivable exceeds 600million and the proposed fund-raising is 450million

Introduction to deep learning and neural networks

GIS remote sensing R language learning see here

Vs code runs "yarn run dev" and reports "yarn": the file XXX cannot be loaded

基于STM32F103ZET6库函数外部中断实验

VS code 运行yarn run dev 报yarn : 无法加载文件XXX的问题

芯动联科冲刺科创板:年营收1.7亿 北方电子院与中城创投是股东

什么是SSR/SSG/ISR?如何在AWS上托管它们?

Keras deep learning practice (12) -- facial feature point detection
随机推荐
基础数据类型和复杂数据类型
Oracle 获取月初、月末时间,获取上一月月初、月末时间
Market status and development prospect forecast of global 4-methyl-2-pentanone industry in 2022
Is it safe to buy stocks and open an account on the account opening link of the securities manager? Ask the great God for help
通过 G1 GC Log 重新认识 G1 垃圾回收器
Running lantern experiment based on stm32f103zet6 library function
Market status and development prospect forecast of the global infusion needle less connector industry in 2022
华大单片机KEIL添加ST-LINK解决方法
基于STM32F103ZET6库函数按键输入实验
Current market situation and development prospect forecast of global 3,3 ', 4,4' - biphenyltetracarboxylic dianhydride industry in 2022
Labelimg usage guide
如何封装调用一个库
Is Guosen Securities a state-owned enterprise? Is it safe to open an account with Guosen Securities?
binder hwbinder vndbinder
工作流自动化 低代码是关键
Making single test so simple -- initial experience of Spock framework
Comment encapsuler un appel à une bibliothèque
1028 List Sorting
[cloud based co creation] the "solution" of Digital Travel construction in Colleges and Universities
流程判断-三目运算-for循环