Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <map>
- #include <string>
- #include <algorithm>
- using namespace std;
- struct date {
- int day, duration, k;
- int begTime, endTime;
- char time[6];
- vector <string> names;
- };
- bool TimeOrder(const date *a, const date *b) {
- return a->day < b->day || a->begTime < b->begTime;
- }
- int main(int argc, char const *argv[])
- {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- string buff;
- // vector <date*> dates;
- map <string, vector<date*>> name_dates;
- int print_day;
- string print_name;
- bool fail;
- int n; fin >> n;
- for (int ii = 0; ii < n; ++ii)
- {
- fin >> buff;
- if (buff == "APPOINT")
- {
- date* x = new date();
- fin >> x->day >> x->time >> x->duration >> x->k;
- x->begTime = atoi(x->time) * 60;
- x->begTime+= atoi(x->time+3);
- x->endTime = x->begTime + x->duration;
- fail = 0;
- for (int ki = 0; ki < x->k; ++ki)
- {
- fin >> buff;
- x->names.push_back(buff);
- for (auto i = name_dates[buff].begin();
- i != name_dates[buff].end(); ++i) {
- if (x->day == (*i)->day &&
- x->begTime < (*i)->endTime &&
- x->endTime > (*i)->begTime) {
- if (!fail) {
- fail = 1;
- fout << "FAIL\n";
- }
- fout << buff << ' ';
- }
- }
- }
- if (!fail) {
- // dates.push_back(x);
- fout << "OK";
- for (auto j = x->names.begin(); j != x->names.end(); ++j) {
- name_dates[*j].push_back(x);
- sort(name_dates[*j].begin(), name_dates[*j].end(), TimeOrder);
- }
- }
- fout << '\n';
- }
- else if (buff == "PRINT") {
- fin >> print_day >> print_name;
- for (auto i = name_dates[print_name].begin();
- i != name_dates[print_name].end(); ++i)
- {
- if (print_day == (*i)->day)
- {
- fout << (*i)->time << ' ' << (*i)->duration;
- for (auto j = (*i)->names.begin(); j != (*i)->names.end(); ++j)
- fout << ' ' << *j;
- fout << '\n';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement