1043. 输出PATest(20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按“PATestPATest....”这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印,直到所有字符都被输出。
输入格式:
输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:redlesPayBestPATTopTeePHPereatitAPPT输出样例:
PATestPATestPTetPTePePee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> int main() { int arr[58][1] = { 0 }, count = 0; char ch; while ((ch = getchar()) != '\n') { arr[ch - 65][0]++; if (ch == 'P' || ch == 'A' || ch == 'T' || ch == 'e' || ch == 's' || ch == 't') count++; } while (count--) { switch (1) { case 1: if (arr[15][0]!= 0) {printf("P"); arr[15][0]--;} //这里的switch是我自己强加的,我就想试试switch的奇技淫巧,这里 case 2: 不加break会一直把case遍历完,我觉得挺有意思的,一般写题直接 if (arr[0][0] != 0) { printf("A"); arr[0][0]--; } if就行了 case 3: if (arr[19][0] != 0) { printf("T"); arr[19][0]--; } case 4: if (arr[36][0] != 0) { printf("e"); arr[36][0]--; } case 5: if (arr[50][0] != 0) { printf("s"); arr[50][0]--; } case 6: if (arr[51][0] != 0) { printf("t"); arr[51][0]--; } } } } |
本文介绍了一个字符串处理问题,要求从给定的字符串中提取特定字符并按PATest模式重新排序输出。通过使用数组记录各目标字符出现次数,再采用循环和switch-case结构实现输出。
2940

被折叠的 条评论
为什么被折叠?



