-
Notifications
You must be signed in to change notification settings - Fork 0
/
1055-1.cpp
93 lines (89 loc) · 1.47 KB
/
1055-1.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
struct person
{
string name;
int height;
};
bool cmp(person a,person b)
{
return a.height==b.height?(a.name<b.name):(a.height>b.height);
}
int main()
{
int n,k;
cin>>n>>k;
vector<person> vec;
for(int i=0;i<n;i++)
{
person p;
cin>>p.name>>p.height;
vec.push_back(p);
}
sort(vec.begin(),vec.end(),cmp);
int row=n/k;
int lastcol=n-(k-1)*row;
vector<string> res;
int times=0;
int flag=0;
for(auto i=0;i<vec.size();)
{
if(flag==0)
{
res.push_back(vec[i].name);
vec.erase(vec.begin());
flag=1;
}
else
{
res.insert(res.begin(),vec[i].name);
vec.erase(vec.begin());
flag=0;
}
times++;
if(times==lastcol)
{
flag=0;
times=0;
for(int i=0;i<res.size()-1;i++)
{
cout<<res[i]<<' ';
}
cout<<res[res.size()-1]<<endl;
res.clear();
break;
}
}
for(int i=0;i<vec.size();)
{
if(flag==0)
{
res.push_back(vec[i].name);
vec.erase(vec.begin());
flag=1;
}
else
{
res.insert(res.begin(),vec[i].name);
vec.erase(vec.begin());
flag=0;
}
times++;
if(times==row)
{
flag=0;
times=0;
for(int i=0;i<res.size()-1;i++)
{
cout<<res[i]<<' ';
}
cout<<res[res.size()-1]<<endl;
res.clear();
}
}
return 0;
}