浙大 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 ...
随机推荐
- CHD 2014迎新杯比赛题解
A. 草滩的魔法学校 分析: 高精度乘法 或 JAVA大数类 很明显 10000 的阶乘已经远远超过 64 位数能表示的范围了.所以我们要用一个比较大的数组来存放这个数.那数组要开多少位合适呢?我们不 ...
- Python基础知识学习_Day8
一.类的扩展方法 1.静态方法 语法:@staticmethod,静态方法不能访问公有属性,不能访问类.可在实例化后直接调用,并且在方法里可以通过self.调用实例变量或类变量. class eat( ...
- Canvas裁剪和Region、RegionIterator
主要是看这边文章学习:http://blog.csdn.net/lonelyroamer/article/details/8349601 Region.op参数 DIFFERENCE(0), //最终 ...
- magento产品批量导出导入
magento产品批量导出导入 博客分类: WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra ExcelMobile配置管理XML ...
- 梅特卡夫法则(Metcalfe's law)
如果一个网络中有n个人,那么网络对于每个人的价值与网络中其他人的数量成正比,于是网络对于所有人的总价值与n*(n-1)成正比.
- HTML4基础
form 表单 首先,讨论“控件”(下面很多都是新控件, ...
- 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解
1. http://bbs.wuyou.com/forum.php?mod=viewthread&tid=303679&fromuid=396698
- c#中命令copy已退出,返回值为1
c#中命令copy已退出,返回值为1 本正经的道:董姐刚才你说的修心养性其中的'修心'我 有孕在身刚好由戴梦瑶顶替了她的位置按照的指示 ╋旆呆 湎术葶页 邾箕砜笳 烦璜卿廑 奶奶个腿儿的等下次非让你 ...
- python入门必备知识总结
人生苦短,我用python.看图说话 一.python简介与发展: python 是一种面向对象的解释性计算机程序设计语言. python由荷兰人Guido van Rossum 于1989年发明. ...
- 学习自动化工具gulp
<什么是gulp>官网地址:http://gulpjs.com/ gulp是可以自动化执行任务的工具,在开发流程里,一定有一些动作需要手工的重复的去执行,例如: ·把一个文件拷贝到另外一个 ...