13: integer deduplication

Total time limit: 1000ms memory limit: 65536kB
description
given sequence containing n integers, the requirements of the sequence to re-operate. The so-called de-emphasis, is the number of this sequence is repeated for each, retaining only the position of the first occurrence of the number, delete the rest position.

Input
Input consists of two lines:
a first line contains a positive integer n (1 <= n <= 20000), the second row indicates the number of digits in the sequence;
second line contains n integers, separated by a space between the integer . Each integer greater than or equal to 10, 100 or less.
Output
only the output line, the output of which will not be repeated in the order of the digital input, and a space between the integer.
Sample input
. 5
10 93 12 is 12 is 75
sample output
10,129,375
Source
Problem (13-9)
resolved : an array mark whether a number appeared, digital input, if there have been no, then direct output, and flag it has appeared over; on the contrary, not treated.

#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+5];
	bool num[110];
	//用于判断每个数是否出现过
	//每个数>=10且<=100,大小110即可 
	memset(num,false,sizeof(num));
	
	for(int i=0;i<n;i++){
		cin>>a[i];
		//如果第一次出现,直接输出,并标记其已经出现过了 
		//num[i]==true表示i这个数已经出现过了 
		if(!num[a[i]]){
			cout<<a[i]<<' ';
			num[a[i]]=true; 
		}
	}
	
	
	return 0;
} 
Published 36 original articles · won praise 0 · Views 338

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/104045525