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;
}

最新文章

  1. 从display:run-in;中学习新技能
  2. SVN出现Invalid authz configuration解决方案
  3. ubuntu入门
  4. 重走java---Step 1
  5. 简单实现异步编程promise模式
  6. 寻找C语言和.NET之间的桥梁
  7. [About me] 关于Alima博主
  8. [Java] HashMap 导致的高 CPU 使用率
  9. FreeMarker辅助
  10. Linux 抓包命令
  11. 全景技术大揭秘,市场核心早洞悉——VR全景加盟
  12. 2017 年的 人生 hard 模式终于结束了,2018年回归初心
  13. CentOS修改yum源
  14. 属性集合java.util.Properties
  15. JVM核心知识体系(转http://www.cnblogs.com/wxdlut/p/10670871.html)
  16. Mysql数据类型、约束、存储引擎
  17. Disruptor入门
  18. mongoDb CPU利用率100%的分析和解决
  19. 【Web】关于Session过期/失效的理解
  20. 【Coursera】Sixth Week(2)

热门文章

  1. xtrabackup在线备份主库,搭建slave,使用gtid模式
  2. google的作恶与不作恶
  3. JavaEE XML XSL转换(XSLT)
  4. MATLAB中的多项式运算
  5. Tomcat 6 跨域的支持
  6. linux下使用autoconf制作Makefile
  7. dwr推送技术深入研究
  8. Sonatype Nexus 服务启动失败问题解决
  9. 无线hacking系统—wifislax
  10. Egret 学习之 入口函数 及开始编写程序(三)