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 ...
随机推荐
- Android(java)学习笔记107-1:通过反射获得带参构造方法并且使用
反射获得带参构造方法并且使用: 1. 获取字节码文件对象 Class c = Class.forName("cn.itcast_01.Person"); 2.获取带参构 ...
- Captcha生成及使用
@Controller @RequestMapping("/PictureCheckCode") public class ServletController { @Request ...
- [改善Java代码]避免对象的浅拷贝
建议43: 避免对象的浅拷贝 我们知道一个类实现了Cloneable接口就表示它具备了被拷贝的能力,如果再覆写clone()方法就会完全具备拷贝能力.拷贝是在内存中进行的,所以在性能方面比直接通过ne ...
- Java Classloader原理分析
类的加载过程指通过一个类的全限定名来获取描述此类的二进制字节流,并将其转化为方法区的数据结构,进而生成一个java.lang.Class对象作为方法区这个类各种数据访问的入口.这个过程通过Jav ...
- Ionic条码扫描
http://m.blog.csdn.net/article/details?id=45843819
- less-1
说在前面的话,为什么用less: 1.需要编写的代码明显变少了 2.css管理更加容易 3.less学习成本低 4.使用less实现配色变得非常容易 5.兼容css3,实现各个浏览器中css的兼容写法 ...
- Jedis - hello world
Maven Dependency: <dependency> <groupId>redis.clients</groupId> <artifactId> ...
- JS定位PDF页码。
由于项目中的PDF文章段落标题有些是英文,对其翻译后需要定位到具体的页码. 查询相关资料及进行尝试后发现可以用如下方法可以实现 function gotoPage(page) { ...
- Newtonsoft.Json.dll序列化为json,null值自动过滤
var jSetting = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}; var json = ...
- ScrollView 与ListView 滑动冲突完美解决
一.介绍ListView高度的设置方法 二.根据实际需求解决冲突问题 一.介绍ListView高度的设置方法 在ScrollView中使用ListView,ListView的高度会不正常. 方式一:在 ...