zoj2481 Unique Ascending Array
来源:互联网 发布:域名访问升级访问 编辑:程序博客网 时间:2024/04/27 22:32
Description
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
Source
#include<cstdio>
#include<algorithm>
using namespace std;
int a[101];
int main()
{
int n,i;
while(scanf("%d",&n)&&n)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
printf("%d",a[0]);
for(i=1;i<n;i++)
{
if(a[i]==a[i-1])
continue;
printf(" %d",a[i]);
}
printf("\n");
}
return 0;
}
- zoj2481 Unique Ascending Array
- ZOJ2481 Unique Ascending Array
- ZOJ2481-Unique Ascending Array
- zoj_2481 Unique Ascending Array
- zoj Unique Ascending Array
- zoj 2481 Unique Ascending Array
- ZOJ 2481 Unique Ascending Array
- zoj 2481 Unique Ascending Array
- ZOJ 2481 Unique Ascending Array
- ZOJ 2481Unique Ascending Array
- zoj 2481 Unique Ascending Array(water still~)
- ZOJ.2481 Unique Ascending Array【子集】 2015/09/24
- array('name', 'unique'),
- Array Question 1 unique string
- LeetCode刷题【Array】 Unique Paths
- leetcode.array--62. Unique Paths
- LeetCode刷题【Array】 Unique Paths II
- leetcode.array--63. Unique Paths II
- Hidden String(模拟)
- S5PV210开发系列七_Nand驱动实现
- 头尾式动画
- C++ 智能指针的简单实现
- 【Linux C 多线程编程】互斥锁与条件变量
- zoj2481 Unique Ascending Array
- ICMP报文格式详解
- Mac解压命令之不解压__MACOSX相关文件
- CSDN极客头条使用指南
- QT实现一个简单的计算器
- S5PV210开发系列八_Yaffs的移植
- javascript中delete对于变量的作用
- 亲戚
- 红黑树