Advertisement
Guest User

input

a guest
Dec 15th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. void process_file(map<int, vector<Road*>> & ver_roads, map<int, vector<Road*>> & hor_roads, int & AVTO)
  2. {
  3.     ifstream fin;
  4.     ofstream fout;
  5.     int N, M;
  6.     int ALL;
  7.     vector<Event*> events;
  8.  
  9.     map<int, User*> last_pos;
  10.  
  11.     fin.open("input.txt");
  12.     fout.open("output.txt");
  13.  
  14.     fin >> N; fin >> M; fin >> AVTO; fin >> ALL;
  15.  
  16.     vector<vector<roads_speeds>> speeds; // массив со всеми скоростями, которые фиксировались на этой дороге.
  17.     speeds.resize(N + M);
  18.  
  19.     for (int i = 0; i < N; ++i)
  20.         read_ver_roads(ver_roads, fin, i);
  21.  
  22.     for (int i = 0 + N; i < M + N; ++i)
  23.         read_hor_roads(hor_roads, fin, i);
  24.  
  25.     while (!fin.eof())
  26.         process_message(ver_roads, hor_roads, fin, fout, events, AVTO, last_pos, speeds);
  27.  
  28.     fin.close();
  29.     fout.close();
  30. }
  31.  
  32. void process_message(map<int, vector<Road*>> & ver_roads, map<int, vector<Road*>> & hor_roads, ifstream & fin, ofstream & fout, vector<Event*> & events, int & AVTO, map<int, User*> & last_pos, vector<vector<roads_speeds>> & speeds)
  33. {
  34.     void (*answer_request[4])(ifstream & fin, ofstream & fout, map<int, vector<Road*>> & ver_roads, map<int, vector<Road*>> & hor_roads, vector<Event*> & events, vector<vector<roads_speeds>> & speeds, int & time_num) =
  35.     { f0, f1, f2, f3 };
  36.  
  37.     string time_str, message_type;
  38.     int time_num;
  39.  
  40.     fin >> time_str;
  41.     fin >> message_type;
  42.     //printf("%s || ", time_str.c_str());
  43.  
  44.     const char* s1 = time_str.substr(0, 2).c_str();
  45.     int hour = atoi(s1);
  46.     //printf("%s - %d || ", s1, hour);
  47.  
  48.     const char* s2 = time_str.substr(3, 2).c_str();
  49.     int min = atoi(s2);
  50.     //printf("%s - %d\n", s2, min);
  51.  
  52.     time_num = hour * 60 + min;
  53.  
  54.     if (message_type == "OBJECT")
  55.     {
  56.         int id, x, y, speed;
  57.  
  58.         fin >> id; fin >> x; fin >> y; fin >> speed;
  59.  
  60.         roads_object object = roads_object(time_str, time_num, id, x, y, speed);
  61.  
  62.         check_offense(ver_roads, hor_roads, events, AVTO, object, last_pos, speeds);
  63.     }
  64.     else // REQUEST
  65.     {
  66.         int type;
  67.         fin >> type;
  68.  
  69.         answer_request[type - 1](fin, fout, ver_roads, hor_roads, events, speeds, time_num);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement