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 父类名" ...
随机推荐
- 关于Business Terminology,你需要了解的三件事
严格意义上来说,商科论文形式的考核,主观因素会有很大的影响.这也是为什么雅思考试中,口语和写作的分数很少有出现满分的原因.除开硬性标准外(如行文逻辑,扣题准确度以及文献资料准确引用等),商科高分论文都 ...
- jQuery中:first,:first-child,first()的使用区别
ul li:first 先获取页面中所有li节点对象数组,然后返回数组中的第一个li节点对象 . :first-child 选择器选取属于其父元素的第一个子元素的所有元素. first() 返回被 ...
- java List的用法
List的用法List包括List接口以及List接口的所有实现类.因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表 ...
- C++ 内存映射
HANDLE hFile = NULL;HANDLE hFileMap = NULL;const viewmapsize = 8 * 1024 * 1024;//8mDWORD highsize,lo ...
- 洛谷 P1833 樱花
题目传送门 解题思路: 就是完全背包和多重背包的混合.处理时间的时候注意一下就行了 AC代码: #include<iostream> #include<cstdio> usin ...
- iOS应用内跳转到指定系统设置页
APP的跳转: 通过[ [UIApplication sharedApplication] openURL:url]这种方法来实现的. iOS 10以后跳转设置页要用 [[UIApplication ...
- HZNU-ACM寒假集训Day8小结 最小生成树
最小生成树(无向图) Kruskal 给所有边按从小到大排序 形成环则不选择(利用并查集) P1546 最短网络 https://www.luogu.com.cn/problem/P1546 #i ...
- docker搭建redis主从集群和sentinel哨兵集群,springboot客户端连接
花了两天搭建redis主从集群和sentinel哨兵集群,讲一下springboot客户端连接测试情况 redis主从集群 从网上查看说是有两种方式:一种是指定配置文件,一种是不指定配置文件 引用地址 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:字符串
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- UML-设计模式-对一组相关的对象使用抽象工厂模式
1.场景 问题: javapos驱动,有2套,一套是IBM的,另一套是NCR的.如: 使用IBM硬件时要用IBM的驱动,使用NCR的硬件时要用NCR的驱动.那该如何设计呢? 注意,此处需要创建一组类( ...