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<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
char str[];
typedef struct info{
int num[];
int len;
info(){
for(int i = ; i < ; i++){
num[i] = ;
}
len = ;
}
}bign; bign a, c; bign add(bign a, bign b){
int carry = ;
bign c;
for(int i = ; i < a.len || i < b.len; i++){
int temp = a.num[i] + b.num[i] + carry;
c.num[i] = temp % ;
carry = temp / ;
c.len++;
}
if(carry != )
c.num[c.len++] = carry;
return c;
}
int main(){
int hashTB[] = {,};
scanf("%s", str);
for(int i = strlen(str) - ; i >= ; i--){
a.num[a.len] = str[i] - '';
hashTB[a.num[a.len]]++;
a.len++;
}
c = add(a, a);
for(int i = ; i < c.len; i++){
hashTB[c.num[i]]--;
}
int tag = ;
for(int i = ; i < ; i++){
if(hashTB[i] != ){
tag = ;
break;
}
}
if(tag == )
printf("Yes\n");
else printf("No\n");
for(int i = c.len - ; i >= ; i--){
printf("%d", c.num[i]);
}
cin >> str;
return ;
}

总结:

1、大整数的记录结构:

  typedef struct info{
    int num[];
    int len;
    info(){
    for(int i = ; i < ; i++){ //全初始化为0,这样在做加法时可以直接循环到最长的数,而不是仅仅循环到最短的数就结束。
      num[i] = ;
    }
    len = ;
    }
  }bign;

2、大整数的加法:

bign add(bign a, bign b){
int carry = ;
bign c;
for(int i = ; i < a.len || i < b.len; i++){ //以长的数位界
int temp = a.num[i] + b.num[i] + carry;
c.num[i] = temp % ;
carry = temp / ;
c.len++;
}
if(carry != )
c.num[c.len++] = carry;
return c;
}

A1023. Have Fun with Numbers的更多相关文章

  1. PAT甲级——A1023 Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  2. [PAT] A1023 Have Fun with Numbers

    [题目大意] 给一个不超过20位的数字,如果将它乘以2得到的数仅仅是原来的数字重新排列得到的,那就输出Yes,下一行输出加倍后的数.如果不是,输出No,下一行输出加倍后的数. [思路] 20位过于庞大 ...

  3. PAT_A1023#Have Fun with Numbers

    Source: PAT A1023 Have Fun with Numbers (20 分) Description: Notice that the number 123456789 is a 9- ...

  4. PAT 大数运算

    PAT中关于大数的有B1017,A1023,A1024 (A-Advance,B-Basic) B1017 1017. A除以B (20) 本题要求计算A/B,其中A是不超过1000位的正整数,B是1 ...

  5. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  6. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  9. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

随机推荐

  1. 记一次用WPScan辅助渗透WordPress站点

    记一次用WPScan辅助渗透WordPress站点 一.什么是WPScan? WPScan 是一个扫描 WordPress 漏洞的黑盒子扫描器,它可以为所有 Web 开发人员扫描 WordPress ...

  2. git 配置别名

    对于常用的git的命令,可以通过配置别名的方式,提高工作效率. $ git config --global alias.co checkout //执行git co 相当于git checkout $ ...

  3. JDK+JAVA+maven+IDEA

    JDK+JAVA https://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html maven+IDEA http://blog.csdn ...

  4. BugPhobia开发篇章:Beta阶段第VIII次Scrum Meeting

    0x01 :Scrum Meeting基本摘要 Beta阶段第八次Scrum Meeting 敏捷开发起始时间 2015/12/22 00:00 A.M. 敏捷开发终止时间 2015/12/22 23 ...

  5. 第六周分析Linux内核创建一个新进程的过程

    潘恒 原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 task_struct结构: ...

  6. Linux内核分析— —构造一个简单的Linux系统MenuOS(20135213林涵锦)

    Linux内核分析— —构造一个简单的Linux系统MenuOS 实验内容 Linux内核的启动过程,从start_kernel到init进程启动 使用实验楼的虚拟机打开shell cd LinuxK ...

  7. HttpServletResponse类学习

    /*//2) 乱码的解决. //设置服务器输出的编码为UTF-8---在BaseServlet处已经已经进行了设置 response.setCharacterEncoding("UTF-8& ...

  8. Online Resource Mapping for SDN Network Hypervisors using Machine Learning

    发表时间:2016 一些定义: self-configuring networks: FlowVisor: FlowVisor是建立在OpenFlow之上的网络虚拟化工具,它可以将物理网络划分成多个逻 ...

  9. [2017BUAA软工]第0次博客作业

    第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? 当初选择计算机专业作为自己报考大学的第一志愿,主要是看重了市场对于计算机行业人士的巨大需求,同时也感慨于计算机行 ...

  10. ActiveMQ应用(1)-安装及示例

    简介: Apache ActiveMQ ™ 是最流行最强大的开源消息及继承模式服务器.i Apache ActiveMQ 速度快,支持多种语言的客户端及代理,可便捷的使用企业集成模式,完整支持JMS1 ...