00-自测4. Have Fun with Numbers
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 file 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>
using namespace std;
int main() {
int i = ;
int j = ;
int len;
int temp;
string num;
//判断是否为输入的副本
bool is_dup = true;
int judge[];
//保存输出结果
int result[];
//保存进位
int counter[]; cin >> num;
len = num.length(); for (i = ; i < ; i++) {
counter[i] = ;
judge[i] = ;
}
//计算输出结果
for (i = len - ; i >= ; i--) {
temp = (num[i] - '');
judge[temp]++;
temp = temp * + counter[i];
result[j++] = temp % ;
if (i != )
counter[i - ] = temp / ;
else {
result[j++] = temp / ;
}
}
if (result[j - ] != )
len = j; for (i = ; i < len; i++) {
judge[result[i]]--;
} for (i = ; i < ; i++) {
if (judge[i] != ) {
is_dup = false;
}
} if (is_dup)
cout << "Yes" << endl;
else
cout << "No" << endl; for (j = len - ; j >= ; j--) {
cout << result[j];
}
return ;
}
00-自测4. Have Fun with Numbers的更多相关文章
- pat00-自测4. Have Fun with Numbers (20)
00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...
- 数据结构练习 00-自测4. Have Fun with Numbers (20)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- 自测-4 Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- PTA 自测-4 Have Fun with Numbers
#include<iostream> #include<string> #include<cstring> #include<vector> using ...
- PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌
-自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...
- LC 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- Using the Task Parallel Library (TPL) for Events
Using the Task Parallel Library (TPL) for Events The parallel tasks library was introduced with the ...
- JavaScript+svg绘制的一个动态时钟
结果图: 代码如下: <!DOCTYPE html> <html> <head> <title>动态时钟</title> </head ...
- WeQuant交易策略—NATR
策略名称:NATR策略关键词:规范真实波幅.价格突破. NATR,是对ATR指标进行了标准化.主要应用于了解价格的震荡幅度和节奏,在窄幅整理行情中用于寻找突破时机.本策略在当前价格高于之前价格一定倍数 ...
随机推荐
- p3792 由乃与大母神原型和偶像崇拜(思维+线段树)
要求 1.修改x位置的值为y 2.查询区间l,r是否可以重排为值域上连续的一段 可以,很lxl 然后一开始思考合并区间,但是发现可以重排序,GG 然后想了特殊性质,比如求和,但是显然可以被叉 这时候我 ...
- 题解——Codeforces Round #507 (based on Olympiad of Metropolises) T2(模拟)
T2还是模拟 枚举一下第一个放哪里 然后贪心的反转即可 虽然我也不会证,但是这题肯定有解qwq #include <cstdio> #include <algorithm> # ...
- Graph Convolutional Networks (GCNs) 简介
Graph Convolutional Networks 2018-01-16 19:35:17 this Tutorial comes from YouTube Video:https://www ...
- Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary
Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary 2017.03.08 ...
- ActiveReports 大数据分析报告:公交车司乘冲突引发的刑事案件
公交车司乘冲突刑事案件总体情况 公交车司乘冲突引发的刑事案件总量稳中有升 (注:本报告界定的“公交车司乘冲突刑事案件”,是指案件诱因为公交车司机与乘客在乘车过程中发生冲突而引发的刑事案件.包括但不限于 ...
- 【使用指南】WijmoJS 前端开发工具包
为方便广大前端开发人员更好的使用 WijmoJS 前端开发工具包,葡萄城专门推出了 WijmoJS 使用指南,该指南详细地介绍了如何把 WijmoJS 各种强大的功能应用到您自己的 Web 项目中,助 ...
- StringBuilder的三种删除方法比较
分别用一千万次循环来比较StringBuilder的三种删除方法所用时间 未避免偶然性,再循环一百次来比较总时间 --主类 public class StringBuilderRemove { pub ...
- vs编译出现 fatal error LNK1281:无法生成 SAFESEH 映像
问题: 在vs编译中我们有时候常常会见到这样的错误,无法生成 SAFESEH 映像,镜像安全问题 解决方法: 1.打开该项目的"属性页"对话框. 2.单击"链接器&quo ...
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
[root@Gris- FMIS2600bak]# tar -zxvf /home/oradata/FMIS2600DMP.tar.gz gzip: stdin: not in gzip format ...
- 深入浅析Spring的AOP实现原理
转载来源:https://www.jb51.net/article/81788.htm AOP(Aspect-OrientedProgramming,面向切面编程),可以说是OOP(Object-Or ...