[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 ...
随机推荐
- Ceph 存储集群4-高级运维:
一.高级运维 高级集群操作主要包括用 ceph 服务管理脚本启动.停止.重启集群,和集群健康状态检查.监控和操作集群. 操纵集群 运行 Ceph 每次用命令启动.重启.停止Ceph 守护进程(或整个集 ...
- ICC教程 - Flow系列 - 概念系列 - ECO (理论+实践+脚本分享)
本文转自:自己的微信公众号<集成电路设计及EDA教程> <ICC教程 - Flow系列 - 概念系列 - ECO (理论+实践+脚本分享)> 这篇推文讲一下数字IC设计中的po ...
- C++输出中文字符
注:本文转载自互联网,感谢作者整理! 1. cout 场景1: 在源文件中定义 const char* str = "中文" 在 VC++ 编译器上,由于Windows环境用 ...
- tensorflow variable scope 变量命名空间和变量共享
import tensorflow as tf def f(): var = tf.Variable(initial_value=tf.random_normal(shape=[2])) return ...
- 《N诺机试指南》(二)C++自带实用函数
1.排序sort函数: 2.查找: 实例: 3. 队列:
- DataGuard---->主库和备库都配置 db_file_name_convert和log_file_name_convert的作用
一.参数说明 [1] db_file_name_convert db_file_name_convert 主数据库和备用数据库的数据文件转换目录对映(如果两数据库的目录结构不一样),如果有多个对映,逐 ...
- Waymo-自动驾驶长尾问题挑战(2019)
尽管Waymo已经在开放道路上积累超过10 Million Miles,Waymo的工程师们仍然发现有层出不穷的新自动驾驶场景待解决. 1.自动驾驶长尾场景举例 场景一:一个骑自行车的人手中拿着一个S ...
- 第二篇 Springboot mybatis generate根据数据库表自动生成实体类、Mapper和Mapper.xml
源码链接:https://pan.baidu.com/s/1iP4UguBufHbcIEv4Ux4wDw 提取码:j6z9 目录结构如下:只需增加一个generatorConfig.xml文件和在po ...
- 实验一 GIT 代码版本管理
实验一 GIT 代码版本管理 实验目的: 1)了解分布式分布式版本控制系统的核心机理: 2) 熟练掌握git的基本指令和分支管理指令: 实验内容: 1)安装git 2)初始配置git ,git ...
- C语言基础五 数组
数组跟变量的区别? 数组是可以在内存中连续存储多个元素的结构,所有元素必须属于相同类型. 格式:元素类型 数组名[元素个数]: 数组的特点: 只能存放单一元素的数据,里面存放的数据成为元素. 数组的声 ...