Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<list>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class People {
- public:
- string surName;
- string cityName;
- string adress;
- };
- void Input(People* l, int n) {
- string surName, cityName, adress;
- // В циклі вводимо дані n разів
- for (int i = 0; i < n; i++) {
- //cout << "Введiть iм'я: ";
- surName = "name";
- //cout << "Введiть посаду: ";
- //cityName = "Kiyv" + i;
- //cout << "Введiть рiк працевлаштування: ";
- //adress = "x";
- //People* e = new People(surName, cityName, adress); // передаємо дані в конструктор
- l[i].surName = surName;
- cout << endl;
- }
- l[0].cityName = "a";
- l[1].cityName = "v";
- l[2].cityName = "a";
- l[3].cityName = "x";
- l[0].adress = "b";
- l[1].adress = "d";
- l[2].adress = "d";
- l[3].adress = "d";
- }
- // Виводимо весь список
- void GetList(People* l, int n) {
- for (size_t i = 0; i < n; i++)
- {
- cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
- }
- //for (auto i : l)
- // cout << "SurName: " << i.surName << "\t" << "City: " << i.cityName << "\t" << "Adress: " << i.adress << endl;
- }
- void GetListParametr(People* l, int n) {
- int count = 1;
- for (int i = 0; i < n; i++) {
- for (int j = i ; j < n; j++) {
- if ((l[i].cityName == l[j +1].cityName) || (l[i].cityName == l[j - 1].cityName)) {
- count++;
- cout << l[i].cityName << " ";
- if (count == 2) break;
- }
- }
- //if ((l[i].cityName != l[j].cityName && count <= 2 && l[i].adress == l[j].adress))
- //{
- // count++;
- // cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
- //}
- //if (l[i].cityName != l[j].cityName && l[i].adress == l[j].adress)
- //{
- // //cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
- // int wasBefore = 0;
- // for (int k = 0; k < i; k++) {
- // if ((l[k].cityName != l[i].cityName) && (l[i].adress == l[j].adress)) {
- // wasBefore += 1; //break;
- // cout << "SurName: " << l[i].surName << "\t" << "City: " << l[k].cityName << "\t" << "Adress: " << l[i].adress << endl;
- // }
- // }
- // if (wasBefore == 1 || wasBefore == 2 || wasBefore == 3) {
- // cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
- // }
- // //break;
- //}
- }
- /*for (auto i : l) {
- for (auto j = i.cityName.begin() + 1; j < i.cityName.begin() + 2; j++) {
- if (i.cityName == && count <= 2) {
- count++;
- cout << "SurName: " << i.surName << "\t" << "City: " << i.cityName << "\t" << "Adress: " << i.adress << endl;
- }
- }
- }*/
- }
- void GetListP(People* l, int n) {
- int k = 0;
- bool was = false;
- People* p;
- p = l;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n+1; j++) {
- if (l[i+1].adress == l[j+1].adress) {
- was = true;
- /*for (int r = 0; r < k; r++)
- {
- if (l[i].adress == p[r].adress)
- was = true;
- if (!was) {
- p[k].adress = l[k].adress;
- cout << l[k].adress << "\n";
- cout << p[k].adress << "\n";
- k++;
- }
- was = false;
- cout << l[i].cityName << "\t" << l[i].adress << "\n";
- cout << p[j].cityName << "\t" << p[j].adress << "\n";
- cout << l[i].cityName << "\t" << l[i].adress << "\n";
- cout << p[k].cityName << "\t" << p[j].adress << "\n";
- }*/
- //cout << l[i].cityName << "\t" << l[i].adress << "\n";
- //cout << p[j].cityName << "\t" << p[j].adress << "\n";
- if (was) {
- cout << l[i].cityName << "\t" << l[i].adress << "\n";
- //cout << p[k].cityName << "\t" << p[j].adress << "\n";
- }
- was = false;
- }
- }
- }
- }
- int main() {
- setlocale(0, "");
- const int n = 4;
- People l[n];
- Input(l, n);
- GetList(l, n);
- cout << endl;
- //GetListParametr(l, n);
- cout << "\n\n";
- GetListP(l, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment