您的位置:首页 > 其它

pat 乙级 1043. 输出PATest(20)

2017-09-06 22:24 393 查看


思路 : 

分别统计 P A T e s t  这六个字符的个数  

依次循环打印    输出一次 次数-1 ;

代码实现:

#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <ctime>

using namespace std;

char a[10005],b[10005];

int main()
{
gets(a);
int len =strlen(a);
int j=0;
int countP=0,countA=0,countT=0,counte=0,counts=0,countt=0;
for (int i=0; i<len;i++) {
if (a[i]=='P') {
countP++;
}
if (a[i]=='A') {
countA++;
}
if (a[i]=='T') {
countT++;
}
if (a[i]=='e') {
counte++;
}
if (a[i]=='s') {
counts++;
}
if (a[i]=='t') {
countt++;
}
}

for (int i=0;i<len;i++) {
if(countP!=0) {
cout<<"P";
countP--;
}
if(countA!=0) {
cout<<"A";
countA--;
}
if(countT!=0) {
cout<<"T";
countT--;
}
if(counte!=0) {
cout<<"e";
counte--;
}
if(counts!=0) {
cout<<"s";
counts--;
}
if(countt!=0) {
cout<<"t";
countt--;
}
}

return 0;
}
提交代码



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: