【PAT甲级】1023 Have Fun with Numbers (20 分)
题意:
输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int vis[];
string s;
int ans[];
int main(){
cin>>s;
int len=s.size();
for(int i=len-;i>=;--i)
++vis[s[i]-''];
int cnt=;
int x=;
for(int i=len-;i>=;--i){
x=(s[i]-'')*;
if(ans[cnt+]+x%>){
ans[++cnt]+=x%-;
++ans[cnt+];
}
else{
ans[++cnt]+=x%;
if(x>)
++ans[cnt+];
}
}
for(int j=;j;--j)
if(ans[j]){
cnt=j;
break;
}
for(int i=;i<=cnt;++i)
--vis[ans[i]];
int flag=;
for(int i=;i<;++i)
if(vis[i])
flag=;
if(flag)
cout<<"No\n";
else
cout<<"Yes\n";
for(int i=cnt;i;--i)
cout<<ans[i];
return ;
}
【PAT甲级】1023 Have Fun with Numbers (20 分)的更多相关文章
- PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- 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 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- PAT 甲级 1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...
- PAT 甲级 1005 Spell It Right (20 分)
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...
- PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)
1058 A+B in Hogwarts (20 分) If you are a fan of Harry Potter, you would know the world of magic ha ...
- PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)
1031 Hello World for U (20 分) Given any string of N (≥) characters, you are asked to form the char ...
随机推荐
- C\C++改变鼠标样式
改变鼠标样式可以使用SetClassLong函数 HCURSOR hcur = LoadCursor(NULL, IDC_CROSS); //加载系统自带鼠标样式 HWND hwnd = GetHWn ...
- poi处理excel自定义日期格式
poi读取excel自定义时间类型时,读取到的是CELL_TYPE_NUMERIC,即数值类型,这个时候如果直接取值的话会发现取到的值和表格中的值不一样,这时应该先判断值是否是时间或者日期类型再进行处 ...
- 探讨LoadRunner的并发用户和集合点
近来跟踪一个项目,发现同事们在执行性能测试时,比较热衷于使用集合点,从概念上认为要得到并发用户就必须设置集合点,认为在执行一个压力测试脚本时,设置了集合点才算是有效的并发用户,没有设置结合点,就认为可 ...
- Node.js Learning Notes
简介 简单的说 Node.js 就是运行在服务端的 JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事件驱动I/O服务 ...
- java篇 之 ==与equals
==是一个比较运算符,基本数据类型比较的是值,引用数据类型比较的是地址值. "=="比"equals"运行速度快,因为"=="只是比较引用. ...
- 一组关于{x}的积分
\[\Large\displaystyle \int_{0}^{1}\left \{ \frac{1}{x} \right \}\mathrm{d}x~,~\int_{0}^{1}\left \{ \ ...
- 解决ifarme在ios下无法使用
在第一层的config 添加 <access origin="*" /><allow-navigation href="*" />< ...
- 2020年英特尔CPU供应短缺将持续
导读 有着相当靠谱的爆料历史的台媒 DigiTimes 报道称,其预计英特尔的 CPU 供应短缺问题,将持续到 2020 年末.对于这样的预测,我们其实早已见怪不怪,毕竟该公司首席执行官 Bob Sw ...
- BZOJ - 2038 小Z的袜子(普通莫队)
题目链接:小Z的袜子 题意:$n$只袜子,$m$个询问,每次回答有多大概率在$[L,R]$区间内抽到两只颜色相同的袜子 思路:普通莫队,如果两个询问左端点在一个块内,则按询问右端点排序,否则按照所在块 ...
- PHP POST请求 字符串和数组传值的区别
最近工作中需要请求一个API,由于之前接过类似的就直接拿来写好的函数使用.但数据死活就是传不过去,一只返回err. 代码如下: function post_params($url, $params,$ ...