搞得我都快强迫症了,用string数组写,可是一个CLEAR卡了我一天,难受
#include<iostream> #include<cstring> #include<string> using namespace std; string a[100005]; int main() { int T, n; int s, z; bool flag; string x; cin >> T; while(T--) { cin >> n; cin >> x; if(n == 1) { cout << x << endl; continue; } int len = x.size(); for(int i = 0; i < n; i++) a[i].clear(); s = 0; z = 0; flag = false; while(z < len) { a[s] += x[z]; if(flag == false) s++; else if(flag == true) s--; if(s == 0) flag = false; else if(s == (n - 1)) flag = true; z++; } for(int i = 0; i < n; i++) cout << a[i]; cout << endl; } return 0; }