【题目大意】

给一个不超过20位的数字,如果将它乘以2得到的数仅仅是原来的数字重新排列得到的,那就输出Yes,下一行输出加倍后的数。如果不是,输出No,下一行输出加倍后的数。

【思路】
20位过于庞大,超出了long long,所以用数组来做,其中的算法核心有竖式乘法的数组计算法。

【tips】

1 判断原数和double原数是否拥有同样数字的方法:

建立一个数组check[0~9],如果原数的第i位是a,则check[a]++;如果double原数的第i位是a,则check[a]--。最后检查check[0~9],只要有一个不为0,则输出No。

2 读入一个字符(包含空格),用char c = getchar();

【AC代码】

 #include<iostream>
#include <algorithm>
using namespace std;
int main()
{
int num[];
int digit = ;
char c;
while ()
{
c = getchar();
if (c == '\n')break;
num[digit] = c - '';
digit++;
}
bool jinwei = ;//进位标志
int i;
int dnum[];
for (i = digit - ; i >= ; i--)
{
dnum[i] = * num[i] + jinwei;
if (dnum[i] >= )
{
dnum[i] -= ;
jinwei = ;
}
else jinwei = ;
}
if (jinwei == )
{
cout << "No" << endl;
cout << ;//输出进位
}
else
{
int check[] = { };
for (i = ; i < digit; i++)
{
check[num[i]]++;
check[dnum[i]]--;
}
for (i = ; i < ; i++)
if (check[i] != )
break;
if (i == )cout << "Yes" << endl;
else cout << "No" << endl;
}
for (i = ; i < digit; i++)
cout << dnum[i];
return ;
}

[PAT] 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. A1023. Have Fun with Numbers

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

  3. PAT 1023 Have Fun with Numbers

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  4. PAT 1023 Have Fun with Numbers[大数乘法][一般]

    1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...

  5. pat 1023 Have Fun with Numbers(20 分)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

  6. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  7. PAT甲级题解-1100. Mars Numbers (20)-字符串处理

    没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...

  8. 【PAT甲级】1100 Mars Numbers (20 分)

    题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  9. PAT A1023

    简单的大数问题,long long并不能容纳21位数字,这是刚开始没有注意到的 #include<iostream> #include<stdlib.h> #include&l ...

随机推荐

  1. [兴趣使然]用python在命令行下画jandan像素超载鸡

    下午刷煎蛋的时候看到 Dthalo 蛋友发的系列像素超载鸡,就想自己试试用python脚本画一个,老男孩视频里的作业真没兴趣,弄不好吧没意思,往好了写,自己控制不好,能力不够. 所以还是找自己有兴趣的 ...

  2. CCF_ 201509-2_日期计算

    水. #include<iostream> #include<cstdio> using namespace std; ] = {{,,,,,,,,,,,,},{,,,,,,, ...

  3. mongodb副本集群搭建

    一.环境介绍 1.机器信息 10.40.6.68 10.40.6.108 10.40.6.110 软件环境为centos 6.x 2.mongodb 下载链接地址 https://www.mongod ...

  4. LeetCode 126. Word Ladder II 单词接龙 II(C++/Java)

    题目: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transfo ...

  5. Python3(四) 分支、循环、条件与枚举

    表达式        表达式(Expression)是运算符(operator)和操作数(operand)所构成的序列 >>> 1 + 1 2 >>> a = [1 ...

  6. C++ 基础--虚构函数

    virtual 函数 示例代码如下: #include <stdio.h> class base { public: virtual void name(){printf("ba ...

  7. 记一次kubernetes驱逐踩坑

    最近在公司的线上服务器上发现了一个现象: 将某个node的kubelet短暂的停掉之后,其上的pod马上会被驱逐,这让笔者大吃一惊,印象之中,停掉kubelet后,该node会变为NotReady状态 ...

  8. 记一次MySQL中Waiting for table metadata lock的解决方法

    最近项目中的数据库查询经常挂起,应用程序启动后也报操作超时.测试人员就说数据库又挂了(貌似他们眼中的连接失败,查询无果都是挂了),通过 show processlist 一看,满屏都是 Waiting ...

  9. 一键安装apache-2.4.38脚本

    [root@lamp scripts]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@lamp scripts ...

  10. ORB-SLAM2 论文&代码学习 —— LocalMapping 线程

    转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12360913.html 本文要点: ORB-SLAM2 Local ...