AC代码如下
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int t;
cin>> t;
while (t--) {
char res1[100] = "", res2[100] = "";
char result1[100] = "";
scanf("\n");
cin.getline(res1, 100);
cin.getline(res2, 100);
// 先获取几个子串 s2 s3 s4 s5
char s2[100] = "", s3[100] = "", s4[100] = "", s5[100] = "";
int k=0;
for (int i =0; i< strlen(res1); ++i) {
if (res1[i] == '<') {
k= 0;
while (res1[i+1] != '>')
s2[k++] = res1[++i];
// 匹配s3
k =0, ++i;
while (res1[i+1] != '<')
s3[k++] = res1[++i];
// 匹配s4
k = 0, ++i;
while (res1[i+1] != '>')
s4[k++] = res1[++i];
// 匹配s5
k= 0, ++i;
while (i< strlen(res1))
s5[k++] = res1[++i];
break;
}
result1[i] = res1[i];
}
// 开始组装
strcat(result1, s2);
strcat(result1, s3);
strcat(result1, s4);
strcat(result1, s5);
// 组装res2
char result2[100] = "";
strncpy(result2, res2, strlen(res2)-3);
strcat(result2, s4);
strcat(result2, s3);
strcat(result2, s2);
strcat(result2, s5);
cout<< result1<< endl<< result2<< endl;
}
return 0;
}