#include <iostream>
#include <cmath>
#include <string>
#include <stack>
#include<queue>
using namespace std;
const int N = 105;
int dir[4][2] = {
0,1,1,0,0,-1,-1,0
};
struct P {
int x, y;
};
int main()
{
P map1[N];
int vis[N];
int vis2[N];
int n;
int k;
cin >> n;
cin >> k;
for (int i = 0; i < n; i++)//the order of train enter
{
cin>>map1[i].x;
vis2[i] = 0;
}
for (int i = 0; i < n; i++)//the order of outing
cin >> vis[i];
for (int i = 0; i < n; i++)
{
for(int j=0;j<n;j++)
if (vis[i] == map1[j].x)
{
map1[j].y = i;
}
}
for (int i = 0; i < n; i++)
cout << map1[i].y;
cout << endl;
int val = 0;
for (int i = 0; i < n; i++)
{
if (vis2[i] == 0)
{
val += 1;
vis2[i] = val;
}
else continue;
int temp = map1[i].y;
for (int j = i + 1; j < n; j++)
if (vis2[j]==0&&map1[j].y < temp) continue;
else if(vis2[j] == 0){
vis2[j] = val;
temp = map1[j].y;
}
for (int j = 0; j < n; j++)
cout << vis2[j];
cout << endl;
}
for (int i = 0, val = 0; i < n; i++)
if (val < vis2[i]) val = vis2[i];
cout << val;
if (val <= k) cout << "ok" << endl;
system("pause");
return 0;
}
/*
9
3
3 6 9 2 4 7 1 8 5
1 2 3 4 5 6 7 8 9
*/
带缓冲的火车车厢重排,我是这么做的,欢迎指教
猜你喜欢
转载自blog.csdn.net/qq_34902939/article/details/85037803
今日推荐
周排行