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 ...
随机推荐
- MyISAM 和 InnoDB
1.MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快,但是不提供事务支持,而InnoDB提供事务支持已经外部键等高级 ...
- Core + Vue 后台管理基础框架1——运行系统
1.down源码 git clone https://github.com/KINGGUOKUN/SystemManagement.git,项目目录如下: 2.还原数据库 找到项目根目录下System ...
- 如何使用Kibana
目录 前言 一.安装 二.加载自定义索引 三.如何搜索数据 四.如何切换中文 五.如何使用控制台 六.可视化图表 七.使用仪表盘 前言 Kibana 是为 Elasticsearch设计的开源分析和可 ...
- Python模块二
os模块是与操作系统交互的一个接口 <em>#和文件夹相关 os.makedirs('dirname1/dirname2') 可生成多层递归目录 os.removedirs('di ...
- 改变 C/C++ 控制台程序的输出颜色和样式
我们经常可以看见Linux自带终端下的许多程序都输出了不同颜色和底纹的字体.最近也想要自己实现一下这种效果,方法是在输出流中插入占位符\033[***. 我从网上收集了一些常用的控制语句,并用以下代码 ...
- pytorch里一些函数的说明记录
THLongStorage *THTensor_(newSizeOf)(THTensor *self); THLongStorage *THTensor_(newStrideOf)(THTensor ...
- Java-字符输入输出(新手)
参考手册: BufferedReader BufferedWriter: 关键字: close() 关闭流,先刷新. newLine() 写一行行分隔符. write() 写一个字符 ...
- Linux 部署Tomcat图文注解 一学就会
导读 安装tomcat前首先要安装对应的jdk并配置Java环境. 安装jdk,请参考:点我直达 安装Tomcat 下载Tomcat包 官网地址:点我直达 Tomcat与jdk兼容关系 注:Tomca ...
- Python中常见的报错名称
Python中常见的报错名称 1.SyntaxError 语法错误.看看是否用Python关键字命名变量,有没有使用中文符号,运算符.逻辑运算符等符号是不是使用不规范. 2.IndentationEr ...
- MySQL笔记(6)-- SQL更新语句日志系统流程
一.背景 在上一篇[MySQL笔记(5)-- SQL执行流程,MySQL体系结构]中讲述了select查询语句在MySQL体系中的运行流程,从连接器开始,到分析器.优化器.执行器等,最后到达存储引擎. ...