Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <queue>
- #include <string>
- #include <map>
- #include <set>
- using namespace std;
- multimap<int, string> temp;
- struct cell {
- int number_m, number_b;
- string driver, mark;
- };
- ostream & operator << (ostream & os, const cell & q) {
- os << q.number_m << " " << q.driver << " " << q.number_b << " " << q.mark << endl;
- return os;
- }
- bool cmp(const cell & a, const cell & b) {
- return a.number_b < b.number_b || a.number_b == b.number_b && a.number_m < b.number_m;
- }
- bool pred (const pair<int, string> & a) {
- return temp.count(a.first) == 1;
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- deque<cell> q;
- multimap<string, cell> t;
- set<string> f;
- int x, n;
- string mark;
- fin >> n;
- while(n--) {
- cell t;
- fin >> t.number_m >> t.driver >> t.number_b >> t.mark;
- q.push_back(t);
- }
- sort(q.begin(), q.end(), cmp);
- for (deque<cell> :: iterator it = q.begin(); it != q.end(); ++it) {
- fout << *it;
- t.insert(make_pair(it -> driver, *it));
- }
- fout << endl; cin >> x;
- for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
- if (it -> second.number_m == x) f.insert(it -> second.driver);
- for (set<string> :: iterator it = f.begin(); it != f.end(); ++it) fout << *it << endl;
- fin >> mark; f.clear(); fout << endl;
- for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
- if (it -> second.mark == mark) f.insert(it -> second.driver);
- for (set<string> :: iterator it = f.begin(); it != f.end(); ++it) fout << *it << endl;
- string old_mark, new_mark;
- fin >> old_mark >> new_mark;
- for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
- if (it -> second.mark == old_mark) it -> second.mark = new_mark;
- for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
- temp.insert(make_pair(it -> second.number_m, it -> second.mark));
- if (find_if(temp.begin(), temp.end(), pred) == temp.end()) fout << "No";
- else fout << find_if(temp.begin(), temp.end(), pred) -> first;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment