【题目大意】

给一个不超过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. js原型和原型链的简单理解

    构造函数创建对象: function Person() { } var person = new Person(); person.name = 'Tian'; console.log(person. ...

  2. 宅在家学不进去吗?试试这些 GitHub 上简单易学的游戏项目吧

    作者:HelloGitHub-小鱼干 这是本人宅在家里的第 4 周,代码不想看,技术文章不想读,都不能愉快学习了我还怎么当一个优秀的需求消化师呢?有没有什么轻松地方法来学习技术呢?想起了小时候金山打字 ...

  3. @ComponentScan注解,basePackages参数通配符

    @ComponentScan(basePackages = "com.ofo.test")当basePackages的直使用通配符,使用**,不能使用*.引用:https://bl ...

  4. WSGI接口

    web server gateway interface:将http请求,响应格式封装起来,让我们可以专心的用python编写web业务. WSGI接口定义的非常简单,它只要求开发者实现一个函数,就可 ...

  5. Python 代码风格规范(Google)

    Python风格规范 分号 tip 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 tip 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Py ...

  6. 说说GAN(生成式对抗网络)

    在Auto-encoder中,input data通过一个encoder神经网络得到一个维度的较低的向量,称这个向量为code,code经过一个decoder神经网络后输出一个output data. ...

  7. 检测并移除WMI持久化后门

      WMI型后门只能由具有管理员权限的用户运行.WMI后门通常使用powershell编写的,可以直接从新的WMI属性中读取和执行后门代码,给代码加密.通过这种方式攻击者会在系统中安装一个持久性的后门 ...

  8. mysql 支持emoji表情

    在mysql插入emoji表情,出现错误: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8A' for column ' ...

  9. mongo操作备忘

    #查看collection内 某个字段条目数 db.dictionary_system.find({"name":"xxx"}).count() #清空某个co ...

  10. 【转载】Python 最强编辑器PyCharm详细使用指南!

    PyCharm 是一种 Python IDE,可以帮助程序员节约时间,提高生产效率.那么具体如何使用呢?本文从 PyCharm 安装到插件.外部工具.专业版功能等进行了一一介绍,希望能够帮助到大家.机 ...