-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile01.cpp
More file actions
60 lines (60 loc) · 1.21 KB
/
file01.cpp
File metadata and controls
60 lines (60 loc) · 1.21 KB
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
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
string breaktokey(string s,int k){
char*ptr=strtok((char*)s.c_str()," ");
k--;
while(k>0){
ptr=strtok(NULL," ");
k--;
}
return (string)ptr;
}
int numify(string s){
int ans=0;
int p=1;
for(int i=s.length()-1;i>=0;i--){
ans+=(s[i]-'0')*p;
p*=10;
}
return ans;
}
bool lexi_compare(pair<string,string> a,pair<string,string> b){
return a.second < b.second;
}
bool num_compare(pair<string,string> a,pair<string,string> b){
return numify(a.second)<numify(b.second);
}
int main(){
int n;
cin>>n;
cin.get();
pair<string,string>s[1000];
for(int i=0;i<n;i++){
getline(cin,s[i].first);
}
int k;
string reversal;
string type;
cin>>k>>reversal>>type;
for(int i=0;i<n;i++){
s[i].second=breaktokey(s[i].first,k);
}
if(type=="numeric"){
sort(s,s+n,num_compare);
}
else{
sort(s,s+n,lexi_compare);
}
if(reversal=="true"){
for(int i=0;i<=n/2;i++){
swap(s[i],s[n-i-1]);
}
}
for(int i=0;i<n;i++){
cout<<s[i].first<<endl;
}
return 0;
}