返回

ZOJ 2481 Unique Ascending Array

发布时间:2022-11-20 15:17:19 258

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

 

用unique函数就好了

#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
#define rep(i,j,k) for (int i=j;i<=k;i++)
#define per(i,j,k) for (int i=j;i>=k;i--)
#define inone(x) scanf("%d",&x)
#define intwo(x,y) scanf("%d%d",&x,&y)
typedef pair<int,int> pii;
const int N=1e5+10;
const int mod=1e9+7;
int T, n,a[N];

int main()
{
while(~inone(n)&&n)
{
rep(i,1,n) inone(a[i]);
sort(a+1,a+n+1);
int m=unique(a+1,a+n+1)-a-1;
rep(i,1,m) printf("%d%s",a[i],i==m?"\n":" ");
}
return 0;
}

 

 

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
ZOJ 2417 Lowest Bit 2022-11-20 14:50:14