#include <bits/stdc++.h>
using namespace std;
struct Data{
string Name, Sdt, Date;
};
bool check(string s){
for(auto x : s){
if(!isdigit(x)){
return false;
}
}
return true;
}
string ChuanHoa(string s, string &tmp){
stringstream ss(s);
string token;
vector<string> vt;
while(ss >> token){
vt.push_back(token);
}
string x = "";
for(int i = 0; i < vt.size() - 1; i++){
x += vt[i];
if(i != vt.size() - 2){
x += " ";
}
}
tmp = x;
return vt[vt.size() - 1];
}
bool cmp(Data x, Data y){
string hx, hy, kx, ky;
hx = ChuanHoa(x.Name, kx);
hy = ChuanHoa(y.Name, ky);
if(hx == hy){
return kx < ky;
}
return hx < hy;
}
int main(){
ifstream in; in.open("SOTAY.txt");
ofstream out; out.open("DIENTHOAI.txt");
Data a[1000];
string s;
string tmp;
int n = 0;
bool mark1 = true, mark2 = true;
while(getline(in, s)){
if(s.find("/") != string::npos){
tmp = s;
}
else if(check(s) == false){
a[n].Name = s;
mark1 = false;
}
else{
a[n].Sdt = s;
mark2 = false;
}
if(mark1 == false && mark2 == false){
a[n].Date = tmp;
++n;
mark1 = true; mark2 = true;
}
}
sort(a, a + n, cmp);
for(int i = 0; i < n; i++){
out << a[i].Name << ": " << a[i].Sdt << " " << a[i].Date << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgRGF0YXsKCXN0cmluZyBOYW1lLCBTZHQsIERhdGU7Cn07Cgpib29sIGNoZWNrKHN0cmluZyBzKXsKCWZvcihhdXRvIHggOiBzKXsKCQlpZighaXNkaWdpdCh4KSl7CgkJCXJldHVybiBmYWxzZTsKCQl9Cgl9CglyZXR1cm4gdHJ1ZTsKfQoKc3RyaW5nIENodWFuSG9hKHN0cmluZyBzLCBzdHJpbmcgJnRtcCl7CglzdHJpbmdzdHJlYW0gc3Mocyk7CglzdHJpbmcgdG9rZW47Cgl2ZWN0b3I8c3RyaW5nPiB2dDsKCXdoaWxlKHNzID4+IHRva2V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