Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include <functional>
- #include<string>
- #include<algorithm>
- #include <tuple>
- #include<random>
- #include <iomanip>
- #include <iterator>
- #include<set>
- #include<map>
- #include<string>
- using namespace std;
- random_device r;
- struct List {
- int number;
- string date;
- int code;
- List* priv = nullptr;
- List* next = nullptr;
- List(const int&, string, const int&);
- List(const int&);
- List(const List&);
- };
- void outputfr(List*);
- void outputbh(List*);
- void insert(List* , const int&, string, const int&);
- void eraze(List* , const int&);
- List& moving(List* );
- void quantity(List* );
- int main() {
- List p(3); // создание и ожидание ввода 3 элементов (сначала вводится Номер мед. полиса, потом Дата обращения, после Код диагноза)
- outputfr(&p); // вывод от первого к последнему
- outputbh(&p); // вывод от последнего к первому
- insert(&p, 2, "7 November", 6); //вставка нового узла
- outputfr(&p);
- eraze(&p, 1); // удаление всех узлов с заданным значением кода диагноза
- outputfr(&p);
- List q = moving(&p); // перемещение всех узлов с одинаковым мед. полисом
- outputfr(&q);
- quantity(&p); //Определение количества обращений в одну и туже дату содним и тем же диагнозом и вывод
- }
- List::List(const int& p, string s, const int& o) {
- number = p;
- date = s;
- code = o;
- }
- List::List(const int& a) {
- List* w = this;
- List* q = nullptr;
- int p, o; string s;
- cin >> p >> s >> o;
- this->number = p;
- this->date = s;
- this->code = o;
- for (int i = 0; i < a - 1; ++i) {
- cin >> p >> s >> o;
- w->next = new List(p, s, o);
- q = w;
- w = w->next;
- w->priv = q;
- }
- w->next = this;
- this->priv = w;
- }
- List::List(const List& p) {
- this->next = p.next;
- this->priv = p.priv;
- this->code = p.code;
- this->date = p.date;
- this->number = p.number;
- this->next->priv = this;
- this->priv->next = this;
- delete& p;
- }
- void outputfr(List* s) {
- List* q = s;
- while (1) {
- cout << s->number << ' ' << s->date << ' ' << s->code << " ";
- s = s->next;
- if (s == q)break;
- }
- cout << '\n';
- }
- void outputbh(List* s) {
- s = s->priv;
- List* q = s;
- while (1) {
- cout << s->number << ' ' << s->date << ' ' << s->code << " ";
- s = s->priv;
- if (s == q)break;
- }
- cout << '\n';
- }
- void insert(List* s, const int& a, string u, const int& p) {
- List* w = s;
- List* f = s;
- if (w->number == a) {
- w = new List(a, u, p);
- w->next = s->next;
- s->next->priv = w;
- s->next = w;
- w->priv = s;
- swap(w->code, s->code);
- swap(w->date, s->date);
- return;
- }
- s = s->next;
- while (s != f) {
- if (s->number == a) {
- List* q = new List(a, u, p);
- s->priv->next = q;
- q->priv = s->priv;
- q->next = s;
- s->priv = q;
- return;
- }
- if (s == f->priv) {
- List* q = new List(a, u, p);
- s->next = q;
- q->priv = s;
- q->next = f;
- f->priv = q;
- return;
- }
- s = s->next;
- }
- }
- void eraze(List* s, const int& p) {
- List* q = s;
- List* f = s;
- vector<tuple<int, string, int>>v;
- do {
- if (s->code != p)
- v.push_back({ s->number,s->date,s->code });
- s = s->next;
- } while (s != f);
- s = q;
- int i = 0;
- do {
- if (i >= v.size()) {
- s = s->next;
- delete s->priv;
- continue;
- }
- s = s->next;
- ++i;
- } while (s != f);
- s = q;
- for (int i = 0; i < v.size(); ++i) {
- s->number = get<0>(v[i]);
- s->date = get<1>(v[i]);
- s->code = get<2>(v[i]);
- if (i + 1 == v.size()) {
- s->next = q;
- q->priv = s;
- }
- s = s->next;
- }
- }
- List& moving(List* s) {
- map<int, vector<pair<string, int>>>m;
- List* f = s;
- do {
- if (m.find(s->number) == m.end())
- m.insert({ s->number,{} });
- m[s->number].push_back({ s->date,s->code });
- s = s->next;
- } while (s != f);
- List* q = nullptr; List* w = nullptr; List* z;
- bool d = 0;
- for (auto& a : m) {
- if (a.second.size() > 1) {
- for (auto& b : a.second) {
- if (!d) {
- q = new List(a.first, b.first, b.second);
- d = 1;
- w = q;
- continue;
- }
- w->next = new List(a.first, b.first, b.second);
- z = w;
- w = w->next;
- w->priv = z;
- }
- }
- }
- if (q != nullptr && w != nullptr) {
- w->next = q;
- q->priv = w;
- }
- return *q;
- }
- void quantity(List* s) {
- List* f = s;
- map<string, map<int, int>>m;
- map<int, int>j;
- do {
- auto a = m.find(s->date);
- if (a == m.end()) {
- j.insert({ s->code,1 });
- m.insert({ s->date,j });
- j.clear();
- }
- else {
- if ((*a).second.find(s->code) == (*a).second.end())
- (*a).second.insert({ s->code,1 });
- else
- ++(*a).second.find(s->code);
- }
- s = s->next;
- } while (s != f);
- for (auto& a : m) {
- cout << "Date: " << a.first << '\n';
- cout << " " << "Diagnosis code : number" << '\n';
- for (auto& b : a.second)
- cout << " " << setw(14) << b.first << " : " << b.second << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment