uva-10152-烏龜排序
求從待排序的到期望的順序的最小操作順序,只能進行一個操作,將當前的烏龜拿出來,上面的下移,拿出來的放到最上面
發現voj沒有PE,
解題方法,把倆個串反過來使用,從期望的順序到待排序的順序.
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;getchar();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;
}
posted on 2017-07-04 13:07 好吧,就是菜菜 閱讀(...) 評論(...) 編輯 收藏