Problem G: Pick and Pick
Description:
Captain M has a stack of N books numbered from 1 to N. Every time, he will pick the
A
i
A_i
Ai's book count from the top. Now, give you the picked order of Captain M, please output thr number list after Captian M picked all book.
Input:
Multi test case. First line contains a single number T indicates cases number. For each test case:
First line contains a single number N, the number of books.
Second line contains N numbers, indicates picked order list.
1
≤
T
≤
10
1 \le T \le 10
1≤T≤10
1
≤
N
≤
1000
1 \le N \le 1000
1≤N≤1000
Output:
For each test case, output N number, indicates the book number “JTH” picked.
Sample Input | Sample Output |
---|---|
2 2 1 1 3 2 2 1 | 1 2 2 3 1 |
Hints:
case 1:
the book stack is [2, 1]
round 1, “JTH” picked the first book, book stack became [2].
round 2, “JTH” pickde the first book, book stack became [ ].
the output order is [1, 2].
case 2:
the book stack is [3, 2, 1]
round 1, “JTH” picked the second book, book stack became [3, 1].
round 2, “JTH” pickde the second book, book stack became [1].
round 3, “JTH” pickde the first book, book stack became [ ].
the output order is [2, 3, 1].
Answer:
#include <iostream>
using namespace std;
int main(){
int caseNum, N;
int stack[1001], orderList[1001], output[1001];
cin >> caseNum;
while(1){
cin >> N;
//book stack
for (int j = 0; j < N; j ++){
stack[j] = j + 1;
}
//input order list
for (int i = 0; i < N; i ++){
cin >> orderList[i];
}
//抽出书并且对书重新排序
for (int i = 0; i < N; i ++){
output[i] = stack[orderList[i] - 1];
for (int j = orderList[i] - 1; j < N - 1; j ++){
stack[j] = stack[j + 1];
}
}
//output order
for (int m = 0;m < N; m ++)
cout << output[m] << " ";
}
return 0;
}