1043. 输出PATest(20)
来源:互联网 发布:大富豪3.4源码 编辑:程序博客网 时间:2024/06/06 19:17
给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按“PATestPATest....”这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印,直到所有字符都被输出。
输入格式:
输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:redlesPayBestPATTopTeePHPereatitAPPT输出样例:
PATestPATestPTetPTePePee
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef vector<int>::iterator IT;
int main()
{
string a, b;
cin >> a;
for (int i = 0; i < a.size(); i++)
{
if (a[i] == 'P' || a[i] == 'A' || a[i] == 'T' || a[i] == 'e' || a[i] == 's' || a[i] == 't')
{
continue;
}
else
{
a.erase(i,1);
i--;
}
}//得到只含有需要的字母
sort(a.begin(), a.end());//这个可有可无,进行排序
int A=0, P=0, T=0, e=0, s=0, t=0;
for (int i = 0; i < a.size(); i++)//统计PATest的字符的个数
{
if (a[i] == 'A') { A++; }
if (a[i] == 'P') { P++; }
if (a[i] == 'T') { T++; }
if (a[i] == 'e') { e++; }
if (a[i] == 's') { s++; }
if (a[i] == 't') { t++; }
}
int max = A > P ? A : P;
max = max > T ? max : T;
max = max > e ? max : e;
max = max > s ? max : s;
max = max > t ? max : t;//得到最大的那个数,
for (int i = max; i >= 0; i--)//按照PATest的顺序进行输出,属于那个字母的数字输完了,就不会再输出
{
if (P > 0) { printf("P"); }
if (A > 0) { printf("A"); }
if (T > 0) { printf("T"); }
if (e > 0) { printf("e"); }
if (s > 0) { printf("s"); }//只会输出还剩下的字母
if (t> 0) { printf("t"); }
P--; A--; T--; e--; s--; t--;
}
printf("\n");
return 0;
}
18分钟done
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043.输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- 1043. 输出PATest(20)
- TCP连接的建立与终止
- 01背包(要求恰好装满)
- iOS开发:发短信、发邮件、打电话及摇一摇实现
- Python 获得命令行参数的方法
- unity Transform一些特性,是个小坑(个人亲测)
- 1043. 输出PATest(20)
- 慕课网HTML+CSS基础课程学习(二)
- 得到扩展名,得到验证码的函数,创建表格
- 关于OI
- JAVA之容器类简介
- 图像处理遇到的一些问题整理(OpenCV and Emgu)
- linux实验四
- 时间工具类
- semantic ui 的学习笔记