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 父类名" ...
随机推荐
- Codeforces 176B 经典DP
非常好的一个题目,CF上的DP都比较经典 题意就是 给定一个串A,B,正好执行K次操作,每次操作可以把 A串从中间切开,并调换两部分的位置,问最后得到B串共有多少种不同的切法(只要中间有一次不同,即视 ...
- Linux预习第三章节《重定向与管道符》20200219
- vue插件汇总
浏览了一下,确实不错,另补充以下几个插件(欢迎大家将自己使用的插件留言给我,共同进步): vue-orgchart 可编辑,可导出 JSON 的树形组织图 的VUE组件 viewerjs 强大的图 ...
- Day1-T4
原题目 Describe:注意是“两次及以上”而不是“两种及以上”!! code: #include<bits/stdc++.h> using namespace std; int k,m ...
- SQL的查询结果复制到Excel 带标题Head 有换行符导致换行错乱 的解决方案
将SQL查询到的结果保存为excel有很多方法,其中最简单的就是直接复制粘贴了 1.带Head的复制粘贴 1)先左击红色区域实现选择所有数据 2)随后右击选择Copy with Headers 再粘 ...
- 七牛云存储javascript-sdk和java-sdk的使用
自己做项目使用的是一台阿里云最便宜的服务器,存储空间只有40G,静态资源和动态资源都放在一起.听说七牛云存储注册认证即送10G的免费存储,想着把静态资源放在七牛云上,分担一下阿里云服务器的存储压力. ...
- x264报错No working C compiler found.
现象: 缺少C++部署包 解决 [root@localhost x264]# yum -y install gcc gcc-c++ kernel-devel [root@localhost x264] ...
- PAT Advanced 1030 Travel Plan (30) [Dijkstra算法 + DFS,最短路径,边权]
题目 A traveler's map gives the distances between cities along the highways, together with the cost of ...
- 1.6判断类型toString.call()
之前我都是使用typeof,后来发现它的判断有局限,例如(){}obeject.p.toString.call()解决了 obj.toString()的结果和Object.prototype.toSt ...
- CodeForces - 131C The World is a Theatre(组合数)
题意:已知有n个男生,m个女生.现在要选t个人,要求有至少4个男生,至少1个女生,求有多少种选法. 分析: 1.展开,将分子中的m!与分母中n!相约,即可推出函数C. #pragma comment( ...