zoukankan      html  css  js  c++  java
  • PTA(Basci Level)1043.输出PATest

    给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 PATestPATest.... 这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。

    输入格式:

    输入在一行中给出一个长度不超过 104 的、仅由英文字母构成的非空字符串。

    输出格式:

    在一行中按题目要求输出排序后的字符串。题目保证输出非空。

    输入样例:
    redlesPayBestPATTopTeePHPereatitAPPT
    
    输出样例:
    PATestPATestPTetPTePePee
    
    思路
    • 设置一个数组分别存储PATest每个字符出现的个数,最后输出的时候一直扫描直到数组都为0就好了
    代码
    #include<bits/stdc++.h>
    using namespace std;
    int a[6] = {0};
    int main()
    {
    	string s;
    	getline(cin, s);
    
    	for(int i=0;i<s.size();i++)
    	{
    		switch(s[i])
    		{
    			case 'P': a[0]++; break;
    			case 'A': a[1]++; break;
    			case 'T': a[2]++; break;
    			case 'e': a[3]++; break;
    			case 's': a[4]++; break;
    			case 't': a[5]++; break;
    			default: break;
    		}
    	}
    	int len = 0;
    	for(int i=0;i<6;i++)
            len += a[i];   //统计字母的个数用于控制输出
    	int i = 0;
    	string pat = "PATest";
    	while(len != 0)
    	{
    		if(a[i] != 0)
            {
                cout << pat[i];
                a[i]--;
                len--;
            }
    		i += 1;
    		i %= 6;   //设置指针循环往复扫描数组,直到数组中的所有数字=0
    	}
    	return 0;
    }
    
    
    
    引用

    https://pintia.cn/problem-sets/994805260223102976/problems/994805280074743808

  • 相关阅读:
    python模块--time模块
    python模块--如何相互调用自己写的模块
    Animating Views Using Scenes and Transitions
    fragment 切换
    android textview 设置text 字体
    android intent 5.1
    android EditView ime
    animation of android (4)
    animation of android (3)
    animation of android (2)
  • 原文地址:https://www.cnblogs.com/MartinLwx/p/11896006.html
Copyright © 2011-2022 走看看