Have Fun with Numbers (大数)
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 <string>
#include <algorithm>
using namespace std;
int aa[];
int v1[];
int v2[];
int main()
{
string ss;
while(cin>>ss)
{
int i;
for(i=;i<;i++)
{
aa[i]=;
}
for(i=;i<;i++)
{
v1[i]=;
v1[i]=;
}
int count=;
for(i=ss.length()-;i>=;i--)
{
aa[count++]=ss[i]-'';
v1[ss[i]-'']=;
}
for(i=;i<count;i++)
{
aa[i]=aa[i]*;
}
int tem,len;
for(i=;i<count;i++)
{
if(aa[i]>)
{
tem=aa[i]/;
aa[i+]=aa[i+]+tem;
aa[i]=aa[i]%;
}
}
if(aa[count]==) len=count;
else len=count+;
reverse(aa,aa+len);
for(i=;i<len;i++)
{
v2[aa[i]]=;
}
bool ifis=true;
for(i=;i<;i++)
{
if(v1[i]!=v2[i]) ifis=false;
}
if(ifis) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
for(i=;i<len;i++)
{
cout<<aa[i];
}
cout<<endl;
}
return ;
}
Have Fun with Numbers (大数)的更多相关文章
- PAT 1023 Have Fun with Numbers[大数乘法][一般]
1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...
- hdu 5585 Numbers【大数+同余定理】
Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- ACM学习历程—HDU5585 Numbers(数论 || 大数)(BestCoder Round #64 (div.2) 1001)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 题目大意就是求大数是否能被2,3,5整除. 我直接上了Java大数,不过可以对末尾来判断2和5, ...
- ural 1012. K-based Numbers. Version 2(大数dp)
和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...
- zoj Fibonacci Numbers ( java , 简单 ,大数)
题目 //f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2) import java.io.*; import java.util.*; imp ...
- 2017CCPC秦皇岛 G题Numbers&&ZOJ3987【大数】
题意: 给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n,并且要使得这m个数的或值最小. 思路: 从二进制的角度分析,如果这m个数中有一个数某一位为1,那么最后或起来这一位肯定是为1的, ...
- PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法
和1024一样都是大数据的题,因为位数最多要20位,long long最多19位给一个num,求sum=num+num问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了. #i ...
- UVa 11582 Colossal Fibonacci Numbers! 【大数幂取模】
题目链接:Uva 11582 [vjudge] watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fil ...
- ZOJ - 3987 - Numbers (大数 + 贪心)
参考自:https://blog.csdn.net/u013534123/article/details/78484494 题意: 给出两个数字n,m,把n分成m份,使得以下最小 思路: 或运算只有0 ...
随机推荐
- Java基础知识强化103:Java常量池理解与总结
一.相关概念 1. 什么是常量 用final修饰的成员变量表示常量,值一旦给定就无法改变! final修饰的变量有三种:静态变量.实例变量和局部变量,分别表示三种类型的常量. 2. Class文件中的 ...
- AI 对不起 我还爱着你
艾弗森,对不起,我还爱着你.有时候我自己都不知道自己我怎么了,直到最后才发现,我还爱着你. 那天起,我认识了你,便一发不可收拾.这些天,谢谢你,似乎因为你的影响让我改变了,坚持了许多.致以至今我才发现 ...
- 【数值方法,水题】UVa 10341 - Solve It
题目链接 题意: 解方程:p ∗ e^(−x) + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x^2 + u = 0 (0 <= x <= 1) ...
- 使用迭代器遍历List的时候修改List报ConcurrentModificationException异常的解决办法
为了避免这种异常,我们可以使用CopyOnWriteArrayList来代替ArrayList,CopyOnWriteArrayList支持并发访问,所以同时进行迭代和修改是没有问题的.
- RTC之初始化
RTC为了避免初始化一般有3中方法: 一给MCU的VBAT供电,利用MCU的后备寄存器保存已经设置过时间的标志值,RTC初始化时先查询寄存器值如果是已经设置过则不用初始化设置时间 二 当不给VBUAT ...
- Angular 2 从0到1 (三)
作者:王芃 wpcfan@gmail.com 第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:A ...
- 上传系列:jquery.upload.js
最近想做一个上传的总结,把自己用过的上传插件都写一写,哪天用到的时候就不用再一次的翻阅资料,现在页面上用到的上传插件,原理上都差不多,那我也就不再废话了,下面我主要记录一下几个比较常用的,由简到繁,这 ...
- JAVA HttpsURLConnection 忽略对SSL valid 的验证
有时候我们对https进行测试的时候,经常自签署一个证书给server,这个certificate经常是不能通过验证的,但是我们又要用这个https,所以我们经常来忽略对SSL validation的 ...
- Java加密解密相关
关于解释加密解密中的填充方案: http://laokaddk.blog.51cto.com/368606/461279/ 关于对称加密中的反馈模式: http://blog.csdn.net/aaa ...
- Setup Project 安装项目
从vs2012起,微软已经不支持setup project了.以此纪念一下setup project. 在新建Setup Project 增加安装内容,通常是直接Oupput一个项目,或者直接 ...