题解:P11679 [Algo Beat Contest 001 A] Animal Beheaded
分析
固然可以直接计算下标再用 for 输出,但 string 类型为我们提供了更为简便的 substr 函数。
string s="abcde";
//格式:s.substr(起始位置,截取长度)
cout<<s.substr(1,3);
//输出:bcd,注意下标是从0开始的
细节内容见代码注释。
Code
#include<bits/stdc++.h>
#define i64 long long
using namespace std;
int main(){
ios::sync_with_stdio(false),
cin.tie(nullptr),cout.tie(nullptr);
int n;cin>>n;
string s;cin>>s;
//n 和 s 如题目
cout<<s.substr(n/3,n/3)<<s.substr(0,n/3)<<s.substr(n/3*2,n/3);
//三段,每段的长度都是 n/3
return 0;
}