文章

5

粉丝

153

获赞

0

访问

4.1k

头像
签到
P1324 浙江大学机试题
发布于2023年6月24日 11:21
阅读数 487

// 一个数组存储三个值,记录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;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发