【题目大意】

给一个不超过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. 《 Java 编程思想》CH05 初始化与清理

    < Java 编程思想>CH05 初始化与清理 用构造器确保初始化 在 Java 中,通过提供构造器,类的设计者可确保每个对象都会得到初始化.Java 会保证初始化的进行.构造器采用与类相 ...

  2. Win32实现迷宫

    跟着杨立祥老师的课程,为了完成扫雷的作业,打算先用DFS/BFS实现路径搜索的简单Demo. 生成迷宫: /* 扫雷程序生成方砖 */ #include <stdio.h> #includ ...

  3. Newcoder Wannafly13 B Jxy军训(费马小定理、分数在模意义下的值)

    链接:https://www.nowcoder.com/acm/contest/80/B 题目描述 在文某路学车中学高一新生军训中,Jxc正站在太阳下站着军姿,对于这样的酷热的阳光,Jxc 表示非常不 ...

  4. 使用Spring Cloud Feign 日志查看请求响应

    在使用微服务时,常常会用feign做客户端去调用别的微服务,但是在日志中很难查看到具体的请求和响应.因此,需要把feign默认的日志打开. 日志设置 创建feign配置类 @Configuration ...

  5. 第2章 Java并行程序基础(三)

    2.8 程序中的幽灵:隐蔽的错误 2.8.1 无提示的错误案例 以求两个整数的平均值为例.请看下面代码: int v1 = 1073741827; int v2 = 1431655768; Syste ...

  6. 一文带你了解 C# DLR 的世界

    一文带你了解 C# DLR 的世界 在很久之前,我写了一片文章dynamic结合匿名类型 匿名对象传参,里面我以为DLR内部是用反射实现的.因为那时候是心中想当然的认为只有反射能够在运行时解析对象的成 ...

  7. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

    mongoose报错:DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and wil ...

  8. Ubuntu 18.04 MATLAB 安装及配置

    转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12367846.html 本文要点: Ubuntu 18.04 安装 ...

  9. lua学习之深入函数第二篇

    深入函数 2 非全局的函数 函数是第一类值,函数可以存储到全局变量,局部变量,table 字段中 lua 函数库中的大部分函数存储到 table 字段中 Lib = {} Lib.foo = func ...

  10. Java第一次代码作业汇总

    练习题1:(完数问题) 求100以内的所有完数.(完数:它所有因子之和等于其本身)   方法一: /* 解体思路:1.先找出每个数的所有因子 2.比较因子之和是否与其数本身相等 */ public c ...