浙大 pat 1023题解
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 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 "algorithm"
#include "string"
#include<stdlib.h>
using namespace std;
string Double(string str)
{
int sum;
string result="";
int carry = 0;
int n = str.length();
for(int i=n-1;i>=0;i--)
{
sum = (str[i]-'0')*2;
sum += carry;
result.insert(result.begin(),(sum%10)+'0');
carry = sum/10;
}
if(carry)
{
result.insert(result.begin(),carry+'0');
}
return result;
}
int main()
{
string str,dstr,tstr;
cin >> str;
dstr = Double(str);
tstr = dstr;
sort(str.begin(),str.end());
sort(tstr.begin(),tstr.end());
if(str == tstr)
cout << "Yes"<<endl;
else
cout <<"No" <<endl;
cout << dstr<<endl;
return 0;
}
浙大 pat 1023题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
随机推荐
- LR设置关联---部分内容摘自网络--望见谅
模拟环境---LR机票定票系统设置:首页点击administration-勾选Set LOGIN form's action tag to an error page.选项,点击update. 现在许 ...
- Mac OS 上 CRT 的终端设置
这种设置完全是个人习惯, 切勿效仿!!! 整个终端是 白底黑字 显示方式(奇葩中的奇葩) 1) ANSI Color & Use color scheme 同时勾选 2) Characte ...
- 曾经让我很吐血的Bug(初学者)
1.MSSql 就是 sql Server. 2.用session的时候一定要先实现接口IRequiresSessionState: 3.form表单中type=file传送文件的时候一定要在form ...
- (Nginx学习一)安装和启动及对应文件夹介绍
nginx 安装和启动及对应文件夹介绍 1 安装 官网下载nginx文件 http://nginx.org/en/download.html 解压即可 2 文件夹介绍 在解压后nginx压缩包后发现 ...
- JAVA上连接ubuntu14.04上的Hbase
对于新手来说,连接虚拟机上的Hbase有点繁琐,而且网上的配置不太适合初学者,今天我就整理了一下,希望对你们有帮助,第一次发博客. 1.首先去官网下载Hbase的压缩包.我这里用的是1.2.1 htt ...
- html+css基础篇
2016年11月19号,计划把基础在看一下,听大神说好的东西就要多看几遍,知识是学来用的解决问题的,加油 接下来的是我在自学中的小笔记吧,每天都在保持几个小时的学习思考状态,由于要升本所以学前端的时间 ...
- 获取URL中的参数值
//获取url中ID的值function getParamByName(name, url) { var match = RegExp('[?&]' + name + '=([^&]* ...
- python reduce使用实例
通过一个简单的算法来了解reduce的巧用. 构建函数persistence(n),如果n>9,则返回0.否则继续根据n的权重来分解n,如n=999,则分解为9,9,9.那么将9*9*9=729 ...
- 在网页边角添加GitHub链接图标
在网页边角添加GitHub链接图标 在页面添加HTML一下代码: <a href="https://github.com/you"> <img style=&qu ...
- 个性化推荐系统中的BadCase分析
针对内测用户反馈,由于前一天点击了几个动画,导致第二天推荐的动画屏占比较高,于是开始对此badcase进行分析. 首先分析了该用户的历史观看纪录,由于系统升级,日志缺陷问题,导致该用户10.15-11 ...