Codeforces Round #656 (Div. 3), problem: (B) Restore the Permutation by Merger

https://codeforces.com/problemset/problem/1385/B

LANG : MS C++ 2017 

#include 
#include 
#include 
using namespace std;
int main() {
	int T, n;
	scanf_s("%d", &T);
	int flag[55];
	int num[105];
	while (T--) {
		scanf_s("%d", &n);
		memset(flag, 0, sizeof(flag));
		for (int i = 0; i < 2*n; i++) {
			scanf_s("%d", &num[i]);
		}
		int cnt = 0;
		for (int i = 0; i < 2*n; i++) {
			if (flag[num[i] - 1] == 0) {
				flag[num[i] - 1] = 1;
				if (cnt != 0) {
					printf(" %d", num[i]);
				}
				else {
					printf("%d", num[i]);
				}
				cnt++;
			}
			if (cnt == n) {
				printf("\n");
				break;
			}
		}
	}
	return 0;
}

 

你可能感兴趣的:(Codeforces)