freopen using ++ sin 没有 顺序 mem int
求从待排序的到期望的顺序的最小操作顺序, 只能进行一个操作, 将当前的乌龟拿出来, 上面的下移, 拿出来的放到最上面
发现 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.bubuko.com/infodetail-2152430.html