博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 乙级 1043 输出PATest
阅读量:4618 次
发布时间:2019-06-09

本文共 1194 字,大约阅读时间需要 3 分钟。

1395875-20180628225101955-1833029399.png

输入样例:

redlesPayBestPATTopTeePHPereatitAPPT
输出样例:
PATestPATestPTetPTePePee

思路:建立一张表,字符为关键字,对应字符出现的次数为关键字对应的值。输出“PATest”的时候查表即可。

#include 
#include
#include
#include
#include
#include
#include
using namespace std;void print(const string& s);int main(){ string s; cin>>s; print(s); return 0;}void print(const string& s){ int* p=new int[128]; memset(p,0,sizeof(int)*128); for(string::const_iterator itor=s.begin(); itor!=s.end() ; itor++) p[(int)(*itor)]++; while(p[(int)'P'] && p[(int)'A'] && p[(int)'T'] && p[(int)'e'] && p[(int)'s'] && p[(int)'t']) { cout<<"PATest"; p[(int)'P']--;p[(int)'A']--;p[(int)'T']--;p[(int)'e']--;p[(int)'s']--;p[(int)'t']--; } while(p[(int)'P'] || p[(int)'A'] || p[(int)'T'] || p[(int)'e'] || p[(int)'s'] || p[(int)'t']) { if(p[(int)'P']!=0) { cout<<'P'; p[(int)'P']--; } if(p[(int)'A']!=0) { cout<<'A'; p[(int)'A']--; } if(p[(int)'T']!=0) { cout<<'T'; p[(int)'T']--; } if(p[(int)'e']!=0) { cout<<'e'; p[(int)'e']--; } if(p[(int)'s']!=0) { cout<<'s'; p[(int)'s']--; } if(p[(int)'t']!=0) { cout<<'t'; p[(int)'t']--; } } delete p;}

转载于:https://www.cnblogs.com/FDProcess/p/9241259.html

你可能感兴趣的文章
织梦多域名解析到同一个空间导致打开链接不一致怎么办?
查看>>
Xcode10 library not found for -lstdc++ 找不到问题
查看>>
Mysql 8.0.13如何重置密码
查看>>
发布功能完成
查看>>
excel 合并单元格
查看>>
iOS设计模式简介
查看>>
c# 扩展方法 奇思妙用 高级篇 九:OrderBy(string propertyName, bool desc)
查看>>
C语言中的地址传递(传指针,传递给形参的指针仍然是实参指针的一份拷贝)
查看>>
redis缓存数据库及Python操作redis
查看>>
opencms忘记Admin用户登录密码解决方案
查看>>
forms组件
查看>>
create-react-app 配置sass
查看>>
02_关系数据库
查看>>
在win7电脑中如何查看运行进程的PID标识符
查看>>
[Vue] vue-cli3.0安装
查看>>
shell中如何进行算术运算
查看>>
为什么所有的架构都是糟糕的
查看>>
PageControl的小点点随ScrollView滑动而变动代码
查看>>
(十三)在ASP.NET CORE中使用Options
查看>>
关于博主
查看>>