pat 乙级 1043. 输出PATest(20)


思路 : 


分别统计 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;
}
提交代码





 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值