x2311

Untitled

Jun 8th, 2022
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <queue>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. struct ST {
  12.     string name;
  13.     string phone ;
  14. };
  15.  
  16. void rfile(queue<ST> &q, string path) {
  17.  
  18.  
  19.     ifstream inf(path);
  20.  
  21.  
  22.     ST t;
  23.     stringstream ss;
  24.     queue<ST> АТС2;
  25.     queue<ST> АТС3;
  26.     queue<ST> АТС_mo;
  27.     string st;
  28.     while (getline(inf, st)) {
  29.         ss << st;
  30.         ss >> t.name;
  31.         ss >> t.phone;
  32.         if (t.phone[0] != '2'){
  33.             АТС2.push(t);
  34.         } else if (t.phone[0] == '3'){
  35.             АТС3.push(t);
  36.         } else {
  37.             АТС_mo.push(t);
  38.         }
  39.         ss.clear();
  40.     }
  41.  
  42.     while (!АТС2.empty()) {
  43.         q.push(АТС2.front());
  44.         АТС2.pop();
  45.     }
  46.     while (!АТС3.empty()) {
  47.         q.push(АТС3.front());
  48.         АТС3.pop();
  49.     }
  50.     while (!АТС_mo.empty()) {
  51.         q.push(АТС_mo.front());
  52.         АТС_mo.pop();
  53.     }
  54. }
  55.  
  56. void p(queue<ST> q) {
  57.     while (!q.empty()) {
  58.         cout << q.front().name << " - " << q.front().phone << endl << endl;
  59.         q.pop();
  60.     }
  61. }
  62.  
  63. int main() {
  64.     queue<ST> g;
  65.     rfile(g, "..\\tr.txt");
  66.     p(g);
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment