Tranvick

Untitled

Mar 11th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11. multimap<int, string> temp;
  12. struct cell {
  13.     int number_m, number_b;
  14.     string driver, mark;
  15. };
  16.  
  17. ostream & operator << (ostream & os, const cell & q) {
  18.     os << q.number_m << " " << q.driver << " " << q.number_b << " " << q.mark << endl;
  19.     return os;
  20. }
  21.  
  22. bool cmp(const cell & a, const cell & b) {
  23.     return a.number_b < b.number_b || a.number_b == b.number_b && a.number_m < b.number_m;
  24. }
  25.  
  26. bool pred (const pair<int, string> & a) {
  27.         return temp.count(a.first) == 1;
  28. }
  29.  
  30. int main() {
  31.     ifstream fin("input.txt");
  32.     ofstream fout("output.txt");
  33.     deque<cell> q;
  34.     multimap<string, cell> t;
  35.     set<string> f;
  36.     int x, n;
  37.     string mark;
  38.     fin >> n;
  39.     while(n--) {
  40.         cell t;
  41.         fin >> t.number_m >> t.driver >> t.number_b >> t.mark;
  42.         q.push_back(t);
  43.     }
  44.     sort(q.begin(), q.end(), cmp);
  45.     for (deque<cell> :: iterator it = q.begin(); it != q.end(); ++it) {
  46.         fout << *it;
  47.         t.insert(make_pair(it -> driver, *it));
  48.     }
  49.     fout << endl; cin >> x;
  50.     for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
  51.         if (it -> second.number_m == x) f.insert(it -> second.driver);
  52.     for (set<string> :: iterator it = f.begin(); it != f.end(); ++it) fout << *it << endl;
  53.  
  54.     fin >> mark; f.clear(); fout << endl;
  55.     for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
  56.         if (it -> second.mark == mark) f.insert(it -> second.driver);
  57.     for (set<string> :: iterator it = f.begin(); it != f.end(); ++it) fout << *it << endl;
  58.  
  59.     string old_mark, new_mark;
  60.     fin >> old_mark >> new_mark;
  61.     for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
  62.         if (it -> second.mark == old_mark) it -> second.mark = new_mark;
  63.  
  64.     for (multimap<string, cell> :: iterator it = t.begin(); it != t.end(); ++it)
  65.         temp.insert(make_pair(it -> second.number_m, it -> second.mark));
  66.  
  67.     if (find_if(temp.begin(), temp.end(), pred) == temp.end()) fout << "No";
  68.     else fout << find_if(temp.begin(), temp.end(), pred) -> first;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment