1023 Have Fun with Numbers (20 分)
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<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
using namespace std;
int Array[];
int main()
{
string num;
cin >> num;
int len = num.size();
int flag = ;
int temp = ;
for (int i = len - ; i >= ; i--)
{
Array[num[i] - '']++;
temp = (num[i] - '') * + flag;
flag = ;
if (temp> )
{
temp %= ;
flag = ;
}
Array[temp]--;
num[i] = '' + temp;
}
int flag1 = ;
for(int i=;i<;i++)
if (Array[i]!=)
{
flag1= ;
break;
}
if (flag1)
{
cout << "No" << endl;
if (flag)
cout << "" << num;
else
cout << num;
}
else
{
cout << "Yes" << endl;
if (flag)
cout << "" << num;
else
cout << num;
} }
1023 Have Fun with Numbers (20 分)的更多相关文章
- PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
- 【PAT甲级】1023 Have Fun with Numbers (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)
1069 The Black Hole of Numbers (20 分) For any 4-digit integer except the ones with all the digits ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
- 1023 Have Fun with Numbers (20)(20 point(s))
problem Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 t ...
- PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]
题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...
- PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法
和1024一样都是大数据的题,因为位数最多要20位,long long最多19位给一个num,求sum=num+num问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了. #i ...
- PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)
Two integers are called "friend numbers" if they share the same sum of their digits, and t ...
随机推荐
- 2020ubuntu1804server编译安装redis5笔记(二)配置redis
前一篇笔记记录了ubuntu1804server编译安装redis5,接下来要配置redis5了 网址:https://www.cnblogs.com/qumogu/p/12435694.html 第 ...
- Robotutor Scratch3.0 在线编程平台升级啦!
Robotutor推出的Scratch3.0在线编程平台受到很多编程老师和学员的喜爱,上一个版本我们提供了用户注册,找回密码,个人项目的在线保存和浏览,社区分享评论. 我们根据实际的教学需要,用户角色 ...
- nginx升级不改变配置文件
查看当前版本是:1.10.3 [root@proxy nginx-1.10.3]# /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.10.3b ...
- 今天对C语言不常用的小东西的了解
今天又翻了C语言的书,看到const语句,一时间想不起来到底是干嘛的,看语句const int a=1;明白了这是一个支持常量指定类型的定义常量的关键字,作用几乎与#define一毛一样,但# ...
- 详解分页组件中查count总记录优化
1 背景 研究mybatis-plus(以下简称MBP),使用其分页功能时.发现了一个JsqlParserCountOptimize的分页优化处理类,官方对其未做详细介绍,网上也未找到分析该类逻辑的只 ...
- 详解如何实现斗鱼、B站等全局悬浮窗直播小窗口
最近业务需求需要我们直播返回或者退出直播间时,开一个小窗口在全局继续直播视频,先看效果图. 调研了一下当下主流直播平台,斗鱼.BiliBili等app,都是用WindowManger做的(这个你可以在 ...
- Natas9 Writeup(命令注入)
Natas9: 审计源码,发现关键代码: $key = ""; if(array_key_exists("needle", $_REQUEST)) { $key ...
- iOS包重签名工具,ipa文件重签名,快速签名,SignTool签名工具,好用的签名工具,App重签名
新工具 ProjectTool 已上线 这是一款快速写白包工具,秒级别写H5游戏壳包,可视化操作,极易使用,支持Swift.Objecive-C双语言 QQ交流群:811715780 进入 Proje ...
- JAVA EE,JAVA SE,JAVA ME,JDK,JRE,JVM之间的区别
JAVA EE是开发企业级应用,主要针对web开发有一套解决方案. JAVA SE是针对普通的桌面开发和小应用开发. JAVA ME是针对嵌入式设备开发,如手机. JRE是程序的运行环境 JDK是程序 ...
- Volatile关键字回顾之线程可见性
java中,volatile关键字有两大作用: 1.保证线程的可见性 2.防止指令重排序 这篇文章主要通过典型案例,体现可见性这一特性. 概念: java中,堆内存是线程共享的.而每个线程,都应该有自 ...