文章
5
粉丝
153
获赞
1
访问
5.7k
// 一个数组存储三个值,记录ZOJ的个数
#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
vector<int> counts(3, 0); // Initialize a vector with 3 zeros for Z, O, J
for (char c : s) {
if (c == 'Z') {
counts[0]++;
} else if (c == 'O') {
counts[1]++;
} else if (c == 'J') {
counts[2]++;
}
}
while (counts[0] > 0 || counts[1] > 0 || counts[2] > 0) {
if (counts[0] > 0) {
cout << 'Z';
counts[0]--;
}
if (counts[1] > 0) {
cout << 'O';
counts[1]--;
}
if (counts[2] > 0) {
cout << 'J';
counts[2]--;
}
}
cout << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发