1、http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2481
2、题目:
Given an array of integers A[N], you are asked to decide the shortest array of integers B[M], such that the following two conditions hold.
- For all integers 0 <= i < N, there exists an integer 0 <= j < M, such that A[i] == B[j]
- For all integers 0 =< i < j < M, we have B[i] < B[j]
Notice that for each array A[] a unique array B[] exists.
Input
The input consists of several test cases. For each test case, an integer N (1 <= N <= 100) is given, followed by N integers A[0], A[1], ..., A[N - 1] in a line. A line containing only a zero indicates the end of input.
Output
For each test case in the input, output the array B in one line. There should be exactly one space between the numbers, and there should be no initial or trailing spaces.
Sample Input
8 1 2 3 4 5 6 7 8
8 8 7 6 5 4 3 2 1
8 1 3 2 3 1 2 3 1
0
Sample Output
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3
3、AC代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[110];
int i;
int cmp(int a,int b)
{return a<b;
}
int find(int c)
{for(int j=0;j<i;j++){if(a[j]==c)return 1;}return 0;
}
int main()
{int n,b[110];while(scanf("%d",&n)!=EOF){if(n==0)break;int k=0;for(i=0;i<n;i++){scanf("%d",&a[i]);if(find(a[i])==0)b[k++]=a[i];}sort(b,b+k,cmp);for(int i=0;i<k-1;i++)printf("%d ",b[i]);printf("%d\n",b[k-1]);}return 0;
}