天津大学2019ACM新生赛

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 1T10
1 ≤ N ≤ 1000 1 \le N \le 1000 1N1000

Output:
 For each test case, output N number, indicates the book number “JTH” picked.

Sample InputSample 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值