Problem 1170 - Sorting

Problem 1170 - Sorting
Time Limit: 2000MS   Memory Limit: 131072KB   Difficulty: 5
Total Submit: 2757  Accepted: 721  Special Judge: No
Description
对一组输入的数据进行排序。
对输入的数据,我们有如下的约定:所有的输入数据都为正整数,且都不大于300000000。但是输入的数据可能会有重复,排序时,应将重复的数据合并,即同样的数只处理一次。

Input
只有一组数据,以0结尾。
Output
输出排序后的数据(不含0),其中相同的数应只显示1个。

Sample Input
12500000 10000000 12500000 0
Sample Output
10000000 12500000
Hint
Source
SEUCPC01

/*一种不用快排的方法,
map查找复杂度为logn ,
 则总时间复杂度为nlogn*/

#include<stdio.h>
#include<map>
using namespace std;
int main()
{
    map< int , int> num ;
    map< int , int> :: iterator it_num;
    int x ;
    while( scanf( "%d",&x) == 1)
    {
        if (x == 0) break ;
            num.insert(pair< int , int> (x,1));
    }
    for (it_num = num.begin() ; it_num != num.end() ; it_num ++)
        printf( "%d ",it_num -> first);
    return 0 ;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值