小红书 翻转字符串——AC
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <map> #include <string> #include <vector> #include <set> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <unordered_map> using namespace std; int main(){ string s; cin>>s; int k; cin>>k; for (int i = 0; i < s.size(); i += 2 * k) { reverse(s.begin() + i, min(s.begin() + i + k, s.end())); } cout<<s<<endl; }