2019大学生程序设计大赛——(CCPC)网络选拔赛

水水的C语言即可解决
题意描述:
题目的意思很简单就是说把每一次输入的数放到第一个,后面的数原有次序不变就是依次往后退一就可以,直到执行完最后一个数据结束;
解题思路:
用标记的方法输出即可,先输出book数组里面的每一个数,存的时候从后往前存,那就从第一个开始输出(对于输出的数据进行标记)输完后在输出存储原来数据的数组;具体的看代码自会理解
原文题目:
A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.
Please output the order of cards after m operations.
Input
The first line of input contains two positive integers n and m.(1<=n,m<=105)
The second line of the input file has n Numbers, a sequence of 1 through n.
Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.
Output
Please output the order of cards after m operations. (There should be one space after each number.)
Sample Input
5 3
1 2 3 4 5
3
4
3
Output
3 4 1 2 5
AC代码:

#include
int a[200000],b[200000],book[200000];
int main()
{
	int n,m,i;
	scanf("%d %d", &n,&m);
	for(i=1; i<=n; i++)
	   scanf("%d", &a[i]);
	for(i=m; i>0; i--)
	   scanf("%d", &b[i]);
	printf("%d ", b[1]);
	book[b[1]]=1;
	for(i=2; i<=m; i++)
	{
		if(book[b[i]]==0)
		{
			printf("%d ", b[i]);
			book[b[i]]=1;
		}
	}
	for(i=1; i<=n; i++)
	{
		if(book[a[i]]==0)
		{
			printf("%d ", a[i]);
			book[a[i]]=1;
		}
	}
	printf(" ");
	return 0;
}

你可能感兴趣的:(程序设计比赛,标记)