首页 > 编程语言 > 详细

uva-10152-乌龟排序

时间:2017-07-04 14:22:27      阅读:317      评论:0      收藏:0      [点我收藏+]

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

发现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;
}

  

uva-10152-乌龟排序

原文:http://www.cnblogs.com/shuiyonglewodezzzzz/p/7116124.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!