PTA 自测-4 Have Fun with Numbers
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
int a[] = {}, b[] = { };
string str;
vector<int>doublenum;//记录翻倍后的数值
cin >> str;
int length = str.length();
int j = ;
for (int i = ; i < length; i++)
{
int num;
num = str[i] - '';
a[num]++;
}
int carry = ;
for (int i = length-; i>=; i--)
{
int num = (str[i] - '') * + carry;
if (num >=)
carry = ;
else
carry = ;
int remainder = num % ;
b[remainder]++;
doublenum.push_back(remainder);
}
if (carry == )
doublenum.push_back();
bool judge = true;
for (int i = ; i < ; i++)
{
if (a[i] != b[i])
{
judge = false;
break;
}
}
if (judge)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
for (int i = doublenum.size()-; i>=; i--)
{
cout << doublenum[i];
}
return ;
}
1、用字符串记录数字
2、vector
PTA 自测-4 Have Fun with Numbers的更多相关文章
- pat00-自测4. Have Fun with Numbers (20)
		
00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...
 - 数据结构练习 00-自测4. Have Fun with Numbers (20)
		
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
 - PTA自测-3 数组元素循环右移问题
		
自测-3 数组元素循环右移问题 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M≥0)个位置,即将A中的数据由(A0A1···AN-1)变换为 ...
 - 自测-4 Have Fun with Numbers
		
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
 - 00-自测4. Have Fun with Numbers
		
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
 - PTA (Advanced Level) 1023 Have Fun with Numbers
		
Have Fun with Numbers Notice that the number 123456789 is a 9-digit number consisting exactly the nu ...
 - 『ACM C++』PTA浙大 | 基础题 - Have Fun with Numbers
		
连着这两道都是开学前数构老师的“爱心作业”,还没上课开学就给我们布置作业了,这道题有点小坑,也经常遇到类似的问题,特地拿出来记录一下. -------------------------------- ...
 - PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌
		
-自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...
 - 201521123098 《Java程序设计》 第4周学习总结
		
1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 1. 学习了继承的基本含义,用"class 子类名 extend 父类名" ...
 
随机推荐
- sql select 0 字段 某字段是不在指定的表
			
sql select 0 字段 转自 关于 select 语句中 0 某字段名字,的意思是:该某字段是不在指定的表中的,那么如果要在子查询中利用这个指定的表,且带有这个字段,那么就用这个方式来添加 ...
 - pytorch随笔
			
pytorch中transform函数 一般用Compose把多个步骤整合到一起: 比如说 transforms.Compose([ transforms.CenterCrop(10), transf ...
 - mfc 选择文件(可多选)
			
CFileDialog dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, NULL ); DWORD MAXFILE = ; //2562 is t ...
 - 不要对md5file.read()计算md5值
			
最近遇到的一个问题,我使用以下代码对备份文件计算MD5值: # md5file=open("%s" % outputpath, 'rb') # md5=hashlib.md5(md ...
 - openstack trove实例状态转换条件--Mitaka版本
			
今天研究了一下trove的instance状态转换条件.发现其实设计的挺复杂的.后来思考了一下这样设计的原因.我觉得大致是因为,如果instance的状态全部来自于instance上跑的数据库服务本身 ...
 - 目标检测评价标准(mAP, 精准度(Precision), 召回率(Recall), 准确率(Accuracy),交除并(IoU))
			
1. TP , FP , TN , FN定义 TP(True Positive)是正样本预测为正样本的数量,即与Ground truth区域的IoU>=threshold的预测框 FP(Fals ...
 - cmake的find_package()简单总结
			
遇到的问题 find_package(lzb)出现错误如下: CMake Warning at CMakeLists.txt:37 (find_package): By not providing & ...
 - 二十六、CI框架之分页
			
一.在模型中读取数据库中的表 二.在控制器中添加dividePage函数 三.在View中写入显示代码 四.查看效果,还是挺漂亮的分页效果 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信 ...
 - Swift - 从相册中选择视频(过滤掉照片,使用UIImagePickerController)
			
(本文代码已升级至Swift4) 有时我们需要从系统相册中选择视频录像,来进行编辑或者上传操作,这时使用 UIImagePickerController 就可以实现. 默认情况下,UIImagePic ...
 - gentoo emby-server
			
最近想用 emby-server + kodi 打造家庭播放平台, 在 gentoo 上面先尝试安装配置 emby-server. 首先, 使用 megacoffee 这个 overlay, 这个上面 ...