当前位置:网站首页>1023 Have Fun with Numbers
1023 Have Fun with Numbers
2022-06-27 19:50: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
2469135798High precision addition :
#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(方法)
- Function key input experiment based on stm32f103zet6 Library
- Solution to Maxwell error (MySQL 8.x connection)
- crontab的学习随笔
- Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
- Four years of College for an ordinary graduate
- Bit. Store: long bear market, stable stacking products may become the main theme
- 惊呆!原来 markdown 的画图功能如此强大!
- 判断一个变量是数组还是对象?
- 让单测变得如此简单 -- spock 框架初体验
猜你喜欢

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

实战回忆录:从Webshell开始突破边界

International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding

数组练习 后续补充

爬取国家法律法规数据库

DCC888 :Register Allocation

指针和结构体

“我让这个世界更酷”2022华清远见研发产品发布会圆满成功

PCB线路板蛇形布线要注意哪些问题?

Crawl national laws and Regulations Database
随机推荐
MySQL表的增删改查(基础)
Character interception triplets of data warehouse: substrb, substr, substring
海底电缆探测技术总结
The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder
聊聊毕业季
1024 Palindromic Number
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
GIS遥感R语言学习看这里
Hanoi塔问题
金鱼哥RHCA回忆录:DO447管理项目和开展作业--创建作业模板并启动作业
一种朴素的消失点计算方法
在线文本按行批量反转工具
ABAP随笔-EXCEL-3-批量导入(突破标准函数的9999行)
How to encapsulate and call a library
网络传输是怎么工作的 -- 详解 OSI 模型
指针和结构体
redis集群系列二
数仓的字符截取三胞胎:substrb、substr、substring
308. 二维区域和检索 - 可变 线段树/哈希
国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)