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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
| #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <list> #include <map> #include <string> #include <vector>
using namespace std;
struct Time { int y, m, d; int hh, mm, ss; Time(); Time(char* s); bool operator<(const Time& t) const; Time operator=(const Time& t); void Show(); }; struct Node { int level; string name; Time t; };
struct In { string name; int id; Time t; bool operator<(const In& in) const; };
map<string, list<int> > mod; map<string, int> level; map<int, Node> last; map<int, Node>::iterator res; map<string, Time> sub; vector<In> in; vector<In>::iterator itin;
void init();
int main() { int n, m, num; In data; char str[150], op[150]; string name; while (scanf("%d", &n), n) { init(); for (int i = 0; i < n; i++) { scanf("%s%d%d", str, &num, &m); name = str; level[name] = num; data.name = name; gets(str); for (int j = 0; j < m; j++) { gets(op); for (int k = 0; k < 21; k++) str[k] = op[k]; str[21] = 0; data.t = Time(str); switch (op[23]) { case 'Y': case 'U': data.id = -1; break; case 'O': int k = 29; data.id = 0; while (op[k]) { data.id = data.id * 10 + op[k] - '0'; k++; } break; } in.push_back(data); } } sort(in.begin(), in.end()); for (itin = in.begin(); itin != in.end(); itin++) { list<int>& lst = mod[itin->name]; if (itin->id == -1) { while (!lst.empty()) { num = lst.front(); lst.pop_front(); if (last.find(num) == last.end() || last[num].level < level[itin->name] || last[num].t < sub[itin->name]) { last[num].t = itin->t; last[num].level = level[itin->name]; last[num].name = itin->name; } } sub[itin->name] = itin->t; } else { lst.push_back(itin->id); } } for (res = last.begin(); res != last.end(); res++) { printf("%d ", res->first); (res->second).t.Show(); printf(" BY %s\n", (res->second).name.c_str()); } puts("END"); } return 0; }
Time::Time() { y = m = d = 0; hh = mm = ss = 0; }
Time::Time(char* s) { sscanf(s, "[%d/%d/%d%d:%d:%d]", &y, &m, &d, &hh, &mm, &ss); }
bool Time::operator<(const Time& t) const { if (y != t.y) return y < t.y; else if (m != t.m) return m < t.m; else if (d != t.d) return d < t.d; else if (hh != t.hh) return hh < t.hh; else if (mm != t.mm) return mm < t.mm; else return ss < t.ss; }
Time Time::operator=(const Time& t) { y = t.y; m = t.m; d = t.d; hh = t.hh; mm = t.mm; ss = t.ss; return *this; }
bool In::operator<(const In& in) const { return t < in.t; }
void Time::Show() { printf("[%04d/%02d/%02d %02d:%02d:%02d]", y, m, d, hh, mm, ss); }
void init() { mod.clear(); in.clear(); level.clear(); last.clear(); sub.clear(); }
|