This is a simple string processing question. Enter S1, S2, S3, S4, and S5 and write them down until the second line is output.
The character at the beginning of the first line is entered into the S1 string, and then the character '<' or '>' is entered into the next string, if '\ n' is encountered, S5 has ended.
My code is as follows:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <cstdlib> using namespace STD; int main () {int T; cin> T; getchar (); While (t --) {char ch; char s [5] [1, 100]; // first lineint flag = 0; int I = 0; while (CH = getchar ())! = EOF) {If (CH = '\ n') {s [flag] [I] =' \ 0'; break ;} if (CH = '<' | CH = '>') {s [flag ++] [I] = '\ 0'; I = 0; continue ;} s [flag] [I ++] = CH;} For (Int J = 0; j <5; j ++) cout <s [J]; cout <Endl; // second linewhile (CH = getchar ())! = EOF) {If (CH = '. ') break; cout <ch;} getchar (); cout <s [3] <s [2] <s [1] <s [4] <Endl;} return 0 ;}