Skip to content

E02039: 反反复复

matrix, http://cs101.openjudge.cn/practice/02039/

【黄宇曦 地球与空间科学学院】思路:比较简单,没什么好说的。

cpp
#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using pii = pair<int, int>;
using vi = vector<int>;
using usi = unordered_set<int>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    string str;
    cin >> str;
    string ans = "";
    for (int i = 0; i < n; i++) {
        for (int j = 0; j * n + i < str.size(); j++) {
            // cout << (j * n + (j % 2 == 0 ? i : n - i - 1)) << '\n';
            ans.push_back(str[j * n + (j % 2 == 0 ? i : n - i - 1)]);
        }
    }
    cout << ans << '\n';
    return 0;
}