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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 int a[] = {};
int count1[] = {}; //分别对倍乘前后的位计数
int count2[] = {}; int main(){
string s;
cin >> s;
int len = s.size();
for(int i=;i < s.size();i++){
a[i] = s[i]-'';
}
for(int i=;i < len;i++){
count1[a[i]]++;
}
for(int i=;i < len/;i++){ //翻转
swap(a[i],a[len-i-]);
} int jinwei = ; //倍乘
for(int i=;i <= len;i++){
int num = a[i]* + jinwei;
a[i] = num%;
jinwei = (num)/;
} // for(auto num:a) cout << num << " "; int pos = ;
for(int i=;i >= ;i--){
if(a[i]){pos = i;break;}
}
for(int i=;i <= pos;i++){
count2[a[i]]++;
} int flag = ;
for(int i=;i < ;i++){
if(count1[i] != count2[i])flag = ;
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl; for(int i=pos;i >= ;i--){
cout << a[i];
} return ;
}

_

 

最新文章

  1. SQL Server 解读【已分区索引的特殊指导原则】(1)- 索引对齐
  2. 学习cocos 空程序
  3. [CQOI2011]动态逆序对
  4. checking在浏览器为应用缓存查找更新时触发
  5. JBOSS批量扫描
  6. CSS禁止Chrome谷歌浏览器激活输入框后自动添加橘黄色边框
  7. ios 游戏《魂斗罗》 AL文件素材破解
  8. ||和 &amp;&amp; 符号的赋值运用(转)
  9. Java集合类笔试题
  10. linux下如何产生core,调试core
  11. Java面试题之三
  12. bootstrap悬浮顶部或者底部
  13. Ioc容器依赖注入-Spring 源码系列(2)
  14. Python模糊查询本地文件夹去除文件后缀(7行代码)
  15. css实现视差滚动效果
  16. hibernate框架学习笔记6:事务
  17. 02Framelayout:帧布局
  18. kafka集群方案教程
  19. BZOJ3233:[AHOI2013]找硬币(DP)
  20. Java的起源和发展

热门文章

  1. Docker3之Swarm
  2. 17秋 SDN课程 第二次上机作业
  3. 【Python】【容器 | 迭代对象 | 迭代器 | 生成器 | 生成器表达式 | 协程 | 期物 | 任务】
  4. Redux基础使用
  5. python 排序 由大到小
  6. python中的print()、str()和repr()的区别
  7. python tcp .demo
  8. Python安装第三方库的安装技巧
  9. 使用ajax判断登录用户名
  10. JAVA基础知识总结:十八