1023. Have Fun with Numbers (20)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  8. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

随机推荐

  1. JavaEE XML XPath

    JavaEE XML XPath @author ixenos XPath技术 1 引入 问题:当使用dom4j查询比较深的层次结构的节点(标签,属性,文本),比较麻烦!!!需要遍历DOM树的众多节点 ...

  2. 学习Sass(二)

    前面简单介绍了sass的安装,特点和使用方法等,这里记录下sass的基本语法. 1.变量 2.运算 3.嵌套 4.代码复用 5.高级语法 6.自定义函数 一.变量 变量以$开始,像css属性那样赋值, ...

  3. SAP HANA中创建分析权限(Analytic Privilege)

    Demo Instruction: 假定CustomerID > 100的为VIP客户,我们的权限设置为只显示VIP客户 所使用的Attribute View: ATTR_CUSTOMER_FU ...

  4. SASS相关

    1.安装ruby http://rubyinstaller.org/downloads/ 2.安装SASS gem sources --remove https://rubygems.org/ gem ...

  5. iOS APP中Versions和build版本区别

    version是app发布时用户看到的版本号. build的为了方便开发者多次提交binary, 比如被苹果reject后. 例如,第一次提交version和build都是1.0. 假如审核没过,那么 ...

  6. WebForm 内置对象QueryString、Repeater删改

    一.内置对象QueryString--地址栏数据拼接 格式:?key=value 如:string path = "Default2.aspx?aaa=" + TextBox1.T ...

  7. spring、struts整合

    package com.hanqi.test; public class JISQ { public double add(double a,double b) { return (a+b); } } ...

  8. Hibernate——脏检查和缓存清理机制

    Session到底是如何进行脏检查的呢? 当一个Customer对象被加入到Session缓存中时,Session会为Customer对象的值类型的属性复制一份快照.当Session清理缓存时,会先进 ...

  9. EmbossMaskFilter BlurMaskFilter 学习

    MaskFilter类可以为Paint分配边缘效果.对MaskFilter的扩展可以对一个Paint边缘的alpha通道应用转换.Android包含了下面几种MaskFilter: BlurMaskF ...

  10. 学习任务在继续...css...

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...