-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrchrono.cpp
92 lines (85 loc) · 1.68 KB
/
drchrono.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
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int myrank(const string &s)
{
int i;
int spaces=0,dots=0,commas=0;
for(i=0;i<s.size();i++){
if(s[i]==',') commas++;
if(s[i]=='.') dots++;
if(s[i]==' ') spaces++;
}
if(spaces==2) return 5;
if(dots==1) return 4;
if(dots==2) return 3;
if(spaces==1) return 2;
return 1;
}
int commarank(const string &s)
{
int i;
int spaces=0,dots=0,commas=0;
for(i=0;i<s.size();i++){
if(s[i]==',') commas++;
if(s[i]=='.') dots++;
if(s[i]==' ') spaces++;
}
if(commas==1 && spaces==1) return 4;
if(commas==1) return 2;
return 1;
}
string reorder(string &s)
{
string tmp=s;
int currank=commarank(s);
if(currank==2) {
int idx=s.find(",");
string suffix=s.substr(idx+1);
string prefix=s.substr(0,idx);
return suffix+" "+prefix;
}
if(currank==4){
int idx=s.find(",");
string suffix=s.substr(idx+1);
string prefix=s.substr(0,idx);
return suffix+" "+prefix;
}
return tmp;
}
int main()
{
int N,i;
string s;
getline(cin,s);
sscanf(s.c_str()," %d",&N);
vector<string> v;
map<string,string> M;
for(i=0;i<N;i++){
getline(cin,s);
int idx=s.find(":");
string suffix=s.substr(idx+1);
string prefix=s.substr(0,idx);
prefix=reorder(prefix);
// cout <<suffix<<" "<<prefix<<endl;
if(v.size()==0 || (v.back()!=suffix)) v.push_back(suffix);
if(M.count(suffix)==0){
M[suffix]=prefix;
} else {
string key=M[suffix];
// cout <<key<<":"<<rank(key)<<endl;
// cout <<prefix<<":"<<rank(prefix)<<endl;
if(myrank(key)< myrank(prefix)){
M[suffix]=prefix;
}
}
}
for(i=0;i<v.size();i++){
cout <<M[v[i]]<<":"<<v[i]<<'\n';
}
return 0;
}