From the order of the smallest order to the desired sequence, only one operation will be carried out, the current turtle is taken out, the top of the move down, take out the top
Found Voj no PE,
The method of solving the problem, using the two strings in turn, from the desired order to the order to be sorted.
Ac:170ms
#include <iostream> #include <stdio.h> #include <math.h> #include <memory.h>using namespace std ; int main () {freopen ("D:\\1.txt", "R", stdin), int t;cin >> t;for (int i = 0; i < T; i++) {int n;cin >> n;getc Har (); string a[205];string b[205];string str;for (int j = 0; J < N; j + +) {getline (CIN,STR); a[j] = str;} for (int j = 0; J < N; j + +) {getline (CIN,STR); b[j] = str;} int q = n-1, p = n-1;while (q >= 0) {if (a[q] = = B[p]) p--;q--;} while (P >= 0) {cout << b[p] << endl;p--;} cout << Endl;} return 0;}
uva-10152-Turtle Sort