当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Making single test so simple -- initial experience of Spock framework
基于STM32F103ZET6库函数跑马灯实验
如何封装调用一个库
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
External interrupt experiment based on stm32f103zet6 library function
一种朴素的消失点计算方法
金源高端IPO被终止:曾拟募资7.5亿 儒杉资产与溧阳产投是股东
(LC)46. 全排列
OpenSSL client programming: SSL session failure caused by an obscure function
明美新能源冲刺深交所:年应收账款超6亿 拟募资4.5亿
The Fifth Discipline: the art and practice of learning organization
Market status and development prospect forecast of global functional polyethylene glycol (PEG) industry in 2022
Garbage collector driving everything -- G1
crontab的学习随笔
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
基于STM32F103ZET6库函数外部中断实验
海底电缆探测技术总结
教你打印自己的日志 -- 如何自定义 log4j2 各组件
流程判断-三目运算-for循环
Comment encapsuler un appel à une bibliothèque









