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