-
Notifications
You must be signed in to change notification settings - Fork 0
/
6BigDataSort1431.cpp
51 lines (48 loc) · 1.15 KB
/
6BigDataSort1431.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
#define OFFSET 500000
int Hash[1000001];
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=-500000; i<=500000; i++)//这个一定要放在while里面,否则多次排序的时候就重复存放了
{
Hash[i+OFFSET]=0;
}
for(int j=1; j<=n; j++)//注意边界取值,j<=n
{
int num;
cin>>num;
Hash[num+OFFSET]=1;
}
bool flag=false;
for(int k=500000; k>=-500000&&m!=0; k--)
{
if(Hash[k+OFFSET]==1)
{
if(flag==false)
{
flag=true;
cout<<k;
m--;//为什么不可以把m的变化放在for循环?有可能是逗号的优先级使得循环没有终止
}
else{
cout<<" "<<k;
m--;
}
/*cout<<k;
m--;
if(m!=0)
cout<<" ";
else
{
cout<<endl;
break;
}*/
}
}
}
return 0;
}