-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1055.cpp
94 lines (86 loc) · 1.57 KB
/
1055.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
94
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(pair<string,int> p1,pair<string,int> p2)
{
if(p1.second==p2.second)
return p1.first<p2.first;
return p1.second>p2.second;
}
int main()
{
vector<pair<string,int>> vec;
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
{
string s;
int tall;
cin>>s>>tall;
vec.push_back(make_pair(s,tall));
}
sort(vec.begin(),vec.end(),cmp);
int lastcol=k+n%k;
int flag=0;
int times=0;
vector<string> res;
for(auto iter=vec.begin();iter!=vec.end();)
{
if(flag==0)
{
res.push_back(iter->first);
vec.erase(vec.begin());
flag=1;
}
else
{
res.insert(res.begin(),iter->first);
vec.erase(vec.begin());
flag=0;
}
times++;
if(times==lastcol)
{
flag=0;
times=0;
break;
}
}
for(int i=0;i<res.size()-1;i++)
{
cout<<res[i]<<' ';
}
cout<<res[res.size()-1]<<endl;
res.clear();
for(auto iter=vec.begin();iter!=vec.end();)
{
if(flag==0)
{
res.push_back(iter->first);
vec.erase(vec.begin());
flag=1;
}
else
{
res.insert(res.begin(),iter->first);
vec.erase(vec.begin());
flag=0;
}
times++;
if(times==k)
{
for(int i=0;i<res.size()-1;i++)
{
cout<<res[i]<<' ';
}
cout<<res[res.size()-1]<<endl;
res.clear();
times=0;
flag=0;
}
}
return 0;
}