[Algo Beat Contest 001 A] Animal Beheaded 官方题解

· · 题解

出题人的脑洞真大。

简单的模拟题。

显然是可以直接处理出三个字符串然后按要求顺序输出的,但是使用 substr() 截取显然更加方便,注意截取子串的开头位置和长度。

#include <bits/stdc++.h>
using namespace std;

int n, ans;
string s;

int main() {

    cin >> n >> s;
    cout << s.substr(n / 3, n / 3) + s.substr(0, n / 3) + s.substr(n / 3 * 2);

    return 0;
}