zoj Unique Ascending Array

 Unique Ascending Array
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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


真的感到是一点算法都没有的,我真是无奈了,这题还是很水的!!!
 
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
    int d;
    int flag;
}num[200];
int cmd(node x,node y)
{
    return x.d<y.d;
}
int main()
{
    int i,j,k;
    int n;
    int num2[200];
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
        break;
        for(i=0;i<n;i++)
        {
            num[i].flag=1;
        }
        for(i=0;i<n;i++)
        scanf("%d",&num[i].d);
        sort(num,num+n,cmd);
        for(i=0;i<n;i++)
        {
          for(j=i+1;j<n;j++)
          {
              if(num[i].d==num[j].d)
              {
                  num[j].flag=0;

              }
              else
              {
                  break;
              }

          }
        }
        int t=0;
        for(i=0;i<n;i++)
        {
           if(num[i].flag)
           {
               num2[t]=num[i].d;
               t++;
           }
        }
        for(i=0;i<t-1;i++)
        {
            printf("%d ",num2[i]);
        }
        printf("%d\n",num2[i]);
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值