题解 | #ZOJ#
ZOJ
https://www.nowcoder.com/practice/7557d470617c464f9200d93acf721471
#include <cstring>
#include <iostream>
using namespace std;
#define N 100
int main() {
char str[N];
while (cin >> str) { // 注意 while 处理多个 case
char *p;
p = str;
int countz = 0, counto = 0, countj = 0;
//统计每种字符的个数
while(*p != '\0'){
if (*p == 'Z') countz++;
p++;
}
p = str;
while(*p != '\0'){
if (*p == 'O') counto++;
p++;
}
p = str;
while(*p != '\0'){
if (*p == 'J') countj++;
p++;
}
//字母的个数不为零时,将该字母输出
while(countz != 0 || counto != 0 || countj != 0){
if (countz){
cout<<"Z";
countz--;
}
if (counto){
cout<<"O";
counto--;
}
if (countj){
cout<<"J";
countj--;
}
}
}
}
// 64 位输出请用 printf("%lld")
基恩士成长空间 417人发布