当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

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

国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)

过关斩将,擒“指针”(下)

Buzzer experiment based on stm32f103zet6 library function

DFS and BFS simple principle

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

External interrupt experiment based on stm32f103zet6 library function

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

带你认识图数据库性能和场景测试利器LDBC SNB

Function key input experiment based on stm32f103zet6 Library
随机推荐
Market status and development prospect forecast of global active quality control air sampler industry in 2022
華大單片機KEIL報錯_WEAK的解决方案
shell脚本常用命令(四)
拥抱云原生:江苏移动订单中心实践
Market status and development prospect forecast of the global infusion needle less connector industry in 2022
Making single test so simple -- initial experience of Spock framework
NVIDIA Clara-AGX-Developer-Kit installation
Bit. Store: long bear market, stable stacking products may become the main theme
Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders
现在网上买股票开户身份证信息安全吗?
International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
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
Campus book resource sharing platform
DFS and BFS simple principle
信息学奥赛一本通 1335:【例2-4】连通块
Cdga | what is the core of digital transformation in the transportation industry?
指针和结构体
驾驭一切的垃圾收集器 -- G1
过关斩将,擒“指针”(下)
Running lantern experiment based on stm32f103zet6 library function