菜菜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

求从待排序的到期望的顺序的最小操作顺序,只能进行一个操作,将当前的乌龟拿出来,上面的下移,拿出来的放到最上面

发现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  好吧,就是菜菜  阅读(188)  评论(0编辑  收藏  举报