Vla_DOS

Untitled

May 7th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. class People {
  8. public:
  9.     string surName;
  10.     string cityName;
  11.     string adress;
  12.  
  13. };
  14.  
  15. void Input(People* l, int n) {
  16.     string surName, cityName, adress;
  17.  
  18.  
  19.     // В циклі вводимо дані n разів
  20.     for (int i = 0; i < n; i++) {
  21.         //cout << "Введiть iм'я: ";
  22.         surName = "name";
  23.  
  24.         //cout << "Введiть посаду: ";
  25.        
  26.  
  27.         //cityName = "Kiyv" + i;
  28.  
  29.         //cout << "Введiть рiк працевлаштування: ";
  30.         //adress = "x";
  31.  
  32.  
  33.         //People* e = new People(surName, cityName, adress); // передаємо дані в конструктор
  34.         l[i].surName = surName;
  35.  
  36.         cout << endl;
  37.     }
  38.     l[0].cityName = "a";
  39.     l[1].cityName = "v";
  40.     l[2].cityName = "a";
  41.     l[3].cityName = "x";
  42.  
  43.     l[0].adress = "b";
  44.     l[1].adress = "d";
  45.     l[2].adress = "d";
  46.     l[3].adress = "d";
  47. }
  48.  
  49. // Виводимо весь список
  50. void GetList(People* l, int n) {
  51.     for (size_t i = 0; i < n; i++)
  52.     {
  53.         cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  54.     }
  55.     //for (auto i : l)
  56.     //    cout << "SurName: " << i.surName << "\t" << "City: " << i.cityName << "\t" << "Adress: " << i.adress << endl;
  57. }
  58. void GetListParametr(People* l, int n) {
  59.     int count = 1;
  60.  
  61.     for (int i = 0; i < n; i++) {
  62.         for (int j = i ; j < n; j++) {
  63.             if ((l[i].cityName == l[j +1].cityName) || (l[i].cityName == l[j - 1].cityName)) {
  64.                 count++;
  65.                 cout << l[i].cityName << " ";
  66.                 if (count == 2) break;
  67.             }
  68.         }
  69.             //if ((l[i].cityName != l[j].cityName && count <= 2 && l[i].adress == l[j].adress))
  70.             //{
  71.             //    count++;
  72.             //    cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  73.  
  74.             //}
  75.             //if (l[i].cityName != l[j].cityName && l[i].adress == l[j].adress)
  76.             //{
  77.             //    //cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  78.             //    int wasBefore = 0;
  79.             //    for (int k = 0; k < i; k++) {
  80.             //        if ((l[k].cityName != l[i].cityName) && (l[i].adress == l[j].adress)) {
  81.             //            wasBefore += 1; //break;
  82.             //            cout << "SurName: " << l[i].surName << "\t" << "City: " << l[k].cityName << "\t" << "Adress: " << l[i].adress << endl;
  83.  
  84.             //        }
  85.             //    }
  86.             //    if (wasBefore == 1 || wasBefore == 2 || wasBefore == 3) {
  87.             //        cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  88.             //    }
  89.             //    //break;
  90.             //}
  91.        
  92.     }
  93.     /*for (auto i : l) {
  94.         for (auto j = i.cityName.begin() + 1; j < i.cityName.begin() + 2; j++) {
  95.             if (i.cityName ==  && count <= 2) {
  96.                 count++;
  97.                 cout << "SurName: " << i.surName << "\t" << "City: " << i.cityName << "\t" << "Adress: " << i.adress << endl;
  98.             }
  99.  
  100.         }
  101.     }*/
  102. }
  103.  
  104. void GetListP(People* l, int n) {
  105.     int k = 0;
  106.     bool was = false;
  107.     People* p;
  108.     p = l;
  109.     for (int i = 0; i < n; i++) {
  110.         for (int j = i + 1; j < n+1; j++) {
  111.             if (l[i+1].adress == l[j+1].adress) {
  112.                 was = true;
  113.  
  114.                 /*for (int r = 0; r < k; r++)
  115.                 {
  116.                     if (l[i].adress == p[r].adress)
  117.                         was = true;
  118.                     if (!was) {
  119.                         p[k].adress = l[k].adress;
  120.                         cout << l[k].adress << "\n";
  121.                         cout << p[k].adress << "\n";
  122.                         k++;
  123.                     }
  124.                     was = false;
  125.                     cout << l[i].cityName << "\t" << l[i].adress << "\n";
  126.                     cout << p[j].cityName << "\t" << p[j].adress << "\n";
  127.                     cout << l[i].cityName << "\t" << l[i].adress << "\n";
  128.                     cout << p[k].cityName << "\t" << p[j].adress << "\n";
  129.                 }*/
  130.                 //cout << l[i].cityName << "\t" << l[i].adress << "\n";
  131.                 //cout << p[j].cityName << "\t" << p[j].adress << "\n";
  132.                 if (was) {
  133.  
  134.                     cout << l[i].cityName << "\t" << l[i].adress << "\n";
  135.                     //cout << p[k].cityName << "\t" << p[j].adress << "\n";
  136.  
  137.                 }
  138.                 was = false;
  139.             }
  140.         }
  141.     }
  142. }
  143.  
  144.  
  145. int main() {
  146.     setlocale(0, "");
  147.     const int n = 4;
  148.     People l[n];
  149.  
  150.     Input(l, n);
  151.  
  152.     GetList(l, n);
  153.     cout << endl;
  154.     //GetListParametr(l, n);
  155.     cout << "\n\n";
  156.     GetListP(l, n);
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment