[PAT] A1023 Have Fun with Numbers
【题目大意】
给一个不超过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的更多相关文章
- 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 ...
- A1023. Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- PAT 1023 Have Fun with Numbers
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT 1023 Have Fun with Numbers[大数乘法][一般]
1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...
- 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 ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- PAT A1023
简单的大数问题,long long并不能容纳21位数字,这是刚开始没有注意到的 #include<iostream> #include<stdlib.h> #include&l ...
随机推荐
- SVN本地服务器搭建及在Eclipse中的应用
0.说明在程序开发的时候会有很多的版本,通过手动备份的方式不紧麻烦而且低效易出错.使用SVN来管理版本会方便很多,虽然有一些学习成本,但是学会使用之后会使得开发更加的高效.本文介绍如何在本地搭建svn ...
- what can we do if just only want to truncate transaction log without backup ?
n some circumstances, we just want to truncate transaction log without backup and refuce change data ...
- ## springboot 下策略模式的简单使用
1.灵魂三问 接手前人(已跑路)项目快乐否? 前人项目不写注释懵逼否? 一个方法中一堆if/else,且业务判断条件用简单数字(或英文字母),不带注释,想打人否? 所以,对于上述三个问题,我写 ...
- iRedmail的php由5.4升级到5.6
安装ireadmail时,自带的php是5.4,打算升级到5.6. 升级前注意备份原来的/etc/php-fpm.d下的www.conf,文件内容如下: [inet] user = nginx gro ...
- tensorboard的简单使用
1. 首先保证你已有程序,下面是MLP实现手写数字分类模型的代码实现. 不懂的可以对照注释理解. #输入数据是28*28大小的图片,输出为10个类别,隐层大小为300个节点 from tensorfl ...
- lwip的内存管理
lwip可以不用malloc,而完全用pool,全用全局变量,没看明白怎么实现的. #if LWIP_NETCONN || LWIP_SOCKET LWIP_MEMPOOL(NETBUF, MEMP_ ...
- Kubernetes最新版核心命令
#查看所有namespace的pods运行情况 kubectl get pods --all-namespaces #查看具体pods,记得后边跟namespace名字哦 kubectl get po ...
- 如何分析和研究Log文件 ,如何看日志信息
如何分析和研究Log文件 ,如何看日志信息 . Log 在android中的地位非常重要,要是作为一个android程序员不能过分析log这关,算是android没有入门吧 . 下面我们就来说说如何处 ...
- centos 配置虚拟环境
1.pip install virtualenvwrapper (pip install virtualenv virtualenvwrapper)2.export WORKON_HOME=/home ...
- centos7搭建SVN并配置使用http方式访问SVN服务器
一.检查SVN是否安装 centos7系统自带SVN # rpm -qa subversion [root@localhost ~]# rpm -qa subversion subversion--. ...