-
Notifications
You must be signed in to change notification settings - Fork 0
/
b.cpp
116 lines (104 loc) · 1.67 KB
/
b.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define FF first
#define SS second
#define MOD 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
char g;cin.get(g);
vector< vector< string> > v(n+1);
for(int i=0;i<n;)
{
// cout<<"i = "<<i<<'\n';
string a;
cin>>a;
v[i].pb(a);
char c='a';
cin.get(c);
while(c!='\n')
{
string b;
cin>>b;v[i].pb(b);
cin.get(c);
// cout<<"c = "<<c;
}
i++;
}
// for(int i=0;i<n;i++)
// {
// for(int j=0;j<v[i].size();i++)
// {
// cout<<v[i][j]<<" ";
// }
// cout<<'\n';
// }
int key;
string reversed, ctype;
cin>>key;
cin>>reversed>>ctype;
if(ctype[0]=='l')
{
vector< pair< string, int> > pv;
for(int i=0;i<n;i++)
{
pv.pb({v[i][key-1],i});
}
sort(pv.begin(), pv.end());
if(reversed[0]=='f')
for(int i=0;i<pv.size();i++)
{
for(int j=0;j<v[pv[i].second].size();j++)
{
cout<<v[pv[i].second][j]<<" ";
}
cout<<'\n';
}
else
{
for(int i=((int)pv.size())-1;i>=0;i--)
{
for(int j=0;j<v[pv[i].second].size();j++)
{
cout<<v[pv[i].second][j]<<" ";
}
cout<<'\n';
}
}
}
else
{
vector< pair< int, int> > pv;
for(int i=0;i<n;i++)
{
pv.pb({stoi(v[i][key-1],nullptr,10),i});
}
sort(pv.begin(), pv.end());
if(reversed[0]=='f')
for(int i=0;i<pv.size();i++)
{
for(int j=0;j<v[pv[i].second].size();j++)
{
cout<<v[pv[i].second][j]<<" ";
}
cout<<'\n';
}
else
{
for(int i=((int)pv.size())-1;i>=0;i--)
{
for(int j=0;j<v[pv[i].second].size();j++)
{
cout<<v[pv[i].second][j]<<" ";
}
cout<<'\n';
}
}
}
return 0;
}