#include #include #include #include #include //#include //#include #include #include using namespace std; //using pint = int*; typedef int * pint; //using ppint = int**; typedef int ** ppint; struct class1 { int num_stan1; int number_class1; bool choose1; }; //using pclass1 = class1 *; typedef class1 * pclass1; struct node { class1 cl1; node *next; }; //using pnode = node *; typedef node * pnode; class list { protected: pnode first, last; public: list() { first = last = nullptr; } ~list() { Del_list(); } pnode get_first() { return first; } pnode get_last() { return last; } list(list& beg) { class1 cl1; if (beg.get_first() == nullptr) { this->first = nullptr; this->last = nullptr; } else { pnode p = beg.get_first(); this->Add_first(p->cl1); this->last = this->first; p = p->next; while (p != nullptr) { this->Add_last(p->cl1); p = p->next; }; } } void Add_first(class1 cl); void Add_last(class1 cl); void Read_list(); //void Read_smezh(); class1 Del_node_first(); void Del_after_p(pnode& p, class1& cl); //void Create_list(int i, pint m); void Del_list(); }; void list::Add_first(class1 cl) { pnode q = new node; q->cl1.num_stan1 = cl.num_stan1; q->cl1.number_class1 = cl.number_class1; q->cl1.choose1 = cl.choose1; q->next = nullptr; //q->prew = nullptr; if (first == nullptr) { first = q; last = q; } } void list::Add_last(class1 cl) { pnode q = new node; q->cl1.num_stan1 = cl.num_stan1; q->cl1.number_class1 = cl.number_class1; q->cl1.choose1 = cl.choose1; q->next = nullptr; //q->prew = last; last->next = q; last = q; } void list::Read_list() { pnode q = first; cout << "{"; while (q != nullptr) { cout << q->cl1.num_stan1 << ' ' << q->cl1.number_class1 << '\t'; q = q->next; cout << ' '; } cout << "}"; } class1 list::Del_node_first() { class1 cl; pnode r = first; cl = first->cl1; if (first != nullptr) { first = r->next; } delete r; return cl; } void list::Del_list() { class1 a3; while (first != nullptr) { a3 = Del_node_first(); } last = nullptr; } void list::Del_after_p(pnode& p, class1& cl) { pnode r = p->next; cl = r->cl1; p->next = r->next; delete r; } class mili { protected: pint stan; //masiv staniv int n;//dlina massiva enter int m;//dlina massiva exit int v;//dlina vuh alf int l; class1 spis_sost[10]; public: int count;//kol-vo class list list_ekv[10]; string enter[10]; string exit1[10]; //vuhodnaya stroka string exit[10][10]; //matr vuhodov ppint f_nu,f_nu_; //masiv perehodiv mili() { count = 0; ifstream fin; char f[100] = "mili1.txt"; fin.open(f); if (fin.eof()) { fin.clear(); fin.seekg(0); } else fin.seekg(0); while (!fin.eof()) { fin >> n; cout << n << endl; for (int i = 0; i < n; i++) { fin >> enter[i]; cout << enter[i] << '\t'; } cout << endl; fin >> m; cout << m << endl; stan = new int[m]; for (int i = 0; i < m; i++) { fin >> stan[i]; cout << stan[i] << '\t'; } cout << endl; for (int i = 0; i < m; i++) { spis_sost[i].num_stan1 = stan[i]; spis_sost[i].number_class1 = 0; spis_sost[i].choose1 = false; } f_nu = new pint[m]; for (int i = 0; i < m; i++) { f_nu[i] = new int[n]; } fin >> v; cout << v << endl; for (int i = 0; i < v; i++) { fin >> exit1[i]; cout << exit1[i] << '\t'; } cout << endl; string c; int x; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { fin >> x; f_nu[i][j] = x; cout << f_nu[i][j] << '\t'; } cout << endl; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { fin >> exit[i][j]; cout << exit[i][j] << '\t'; } cout << endl; } } fin.close(); } ~mili() { delete[] stan; for (int i = 0; i < m; i++) { delete[]f_nu[i]; } delete[] f_nu; } pint get_stan() { return stan; } void set_stan(pint ps) { ps = stan; } ppint get_go() { return f_nu; } void set_go(ppint pg) { pg = f_nu; } int get_n() { return n; } void set_n(int n1) { n = n1; } int get_m() { return m; } void set_m(int m1) { m = m1; } int get_l() { return l; } void set_l(int l1) { l = l1; } int get_count() { return count; } void set_count(int count1) { count = count1; } void obrobka(); void obrobka_(); void fragment_clases_1ekv(); void fragment_clases_ekv(); void vuvod(); void new_vuvod(); void New_f_nu(); void vivod_New_f_nu(); void del(); }; void mili::fragment_clases_1ekv() { int i, j, count_local; char local[10]; string s; class1 cl1; cl1.num_stan1 = stan[0]; cl1.number_class1 = 0; for (i = 0; i < m; i++) { if (!spis_sost[i].choose1) { cl1.choose1 = true; spis_sost[i].choose1 = true; spis_sost[i].num_stan1 = i; spis_sost[i].number_class1 = this->count; cl1.num_stan1 = i; cl1.number_class1 = this->count; if (list_ekv[count].get_first() == nullptr) { list_ekv[count].Add_first(cl1); } for (j = i + 1; j < m; j++) { count_local = 0; if (!spis_sost[j].choose1) { for (int c = 0; c < n; c++) { if (exit[j][c] == exit[i][c]) { count_local++; } } if (count_local == n) { cl1.choose1 = true; spis_sost[j].choose1 = true; spis_sost[j].number_class1 = this->count; spis_sost[j].num_stan1 = j; cl1.num_stan1 = j; cl1.number_class1 = this->count; list_ekv[this->count].Add_last(spis_sost[j]); } } } count++; } } } void mili::fragment_clases_ekv() { class1 cl1; pnode p, q; int count_current = count; int i; int num, num2; list list_ekv_current[10]; for (i = 0; i < count; i++) { list_ekv_current[i] = list_ekv[i]; } do { count = count_current; for (i = 0; i < count; i++) { p = list_ekv[i].get_first(); q = p; while (q->next != nullptr) { for (int c = 0; c < n; c++) { num = f_nu[p->cl1.num_stan1][c]; num2 = f_nu[q->next->cl1.num_stan1][c]; if (q->next != nullptr && spis_sost[num].number_class1 != spis_sost[num2].number_class1) { count_current++; list_ekv_current[i].Del_after_p(q, cl1); cl1.number_class1 = count_current - 1; spis_sost[cl1.num_stan1].number_class1 = count_current - 1; if (list_ekv_current[count_current - 1].get_first() == nullptr) { list_ekv_current[count_current - 1].Add_first(spis_sost[cl1.num_stan1]); } else list_ekv_current[count_current - 1].Add_last(spis_sost[cl1.num_stan1]); break; } } q = q->next; } } for (i = 0; i < count_current; i++) { this->list_ekv[i] = list_ekv_current[i]; } } while (count_current != count); int k, g; for (g = 0; g < count_current; g++) { this->list_ekv[g].Read_list(); } cout << endl; new_vuvod(); f_nu_ = new pint[count]; for (int i = 0; i < count; i++) { f_nu_[i] = new int[n]; } for (int i = 0; i < count; i++) { pnode p = this->list_ekv[i].get_first(); for (int j = 0; j < n; j++) { //int num_stan = f_nu[p->cl1.num_stan1][j]; f_nu_[i][j] = list_ekv[spis_sost[f_nu[p->cl1.num_stan1][j]].number_class1].get_first()->cl1.number_class1; //num_stan1; } cout << endl; } } void mili::New_f_nu() { f_nu_ = new pint[count]; for (int i = 0; i < count; i++) { f_nu_[i] = new int[n]; } for (int i = 0; i < count; i++) { pnode p = this->list_ekv[i].get_first(); for (int j = 0; j < n; j++) { int num_stan = f_nu[p->cl1.num_stan1][j]; f_nu_[i][j] = this->list_ekv[spis_sost[num_stan].num_stan1].get_first()->cl1.number_class1; //this->list_ekv[i].get_first()->cl1.num_stan1 } cout << endl; } } void mili::vivod_New_f_nu() { for (int i = 0; i < count; i++) { for (int j = 0; j < n; j++) { cout << f_nu_[i][j] << '\t'; } cout << endl; } } void mili::vuvod() { int k, g; for (g = 0; g < count; g++) { list_ekv[g].Read_list(); } cout << endl; } void mili::new_vuvod() { int g; for (g = 0; g < count; g++) { cout << "{"; cout << list_ekv[g].get_first()->cl1.num_stan1 << '\t'; cout << "} "; } cout << endl; } void mili::del() { int num, num2, i; pnode p, q; class1 cl1; list list_ekv_current[10]; int count_current = count; for (i = 0; i < count; i++) { list_ekv_current[i] = list_ekv[i]; } do { count = count_current; for (int i = 0; i < count; i++) { p = list_ekv[i].get_first(); q = p; while (q->next != nullptr) { for (int c = 0; c < n; c++) { num = f_nu[p->cl1.num_stan1][c]; num2 = f_nu[q->next->cl1.num_stan1][c]; if (q->next != nullptr && spis_sost[num].number_class1 != spis_sost[num2].number_class1) { //spis_sost[num] = spis_sost[num2]; count_current++; list_ekv_current[i].Del_after_p(q, cl1); cl1.number_class1 = count_current - 1; //spis_sost[cl1.num_stan1].choose1 = true; spis_sost[cl1.num_stan1].number_class1 = count_current - 1; //list_sm_current[count_current - 1].Add_first(spis_sost[cl1.num_stan1]); //spis_sost[cl1.number_class1].num_stan1 = stan[j]; if (list_ekv_current[count_current - 1].get_first() == nullptr) { list_ekv_current[count_current - 1].Add_first(spis_sost[cl1.num_stan1]); } else list_ekv_current[count_current - 1].Add_last(spis_sost[cl1.num_stan1]); break; } } q = q->next; } } //vuvod(); for (i = 0; i < count_current; i++) { list_ekv[i] = list_ekv_current[i]; } //new_vuvod(); } while (count_current != count); int k, g; for (g = 0; g < count_current; g++) { list_ekv[g].Read_list(); } cout << endl; } void mili::obrobka() { int j = 0, k = 0; string str; string y; string s,ss_; char ss[20] = "\0"; int s_new, s_cur = 0; do { s = " "; cout << "str="; cin >> str; while (str != ".") { for (int i = 0; i < n; i++) { if (str == enter[i]) { j = i; break; } } s_new = f_nu[s_cur][j]; _itoa_s(s_cur, ss, 10); ss_ = ss; s += ss_ + exit[s_cur][j] + " "; s_cur = s_new; //cout << "str="; cin >> str; } cout << "stroka=" << s << endl; cout << " \n To continue - print yes" << endl; cin >> y; } while (y == "yes"); } void mili::obrobka_() { int j = 0, k = 0; string str; string y; string s,ss_; char ss[20] = "\0"; int s_new, s_cur = 0; do { s = " "; cout << "str="; cin >> str; while (str != ".") { for (int i = 0; i < n; i++) { if (str == enter[i]) { j = i; break; } } s_new = f_nu_[s_cur][j]; _itoa_s(s_cur, ss, 10); ss_ = ss; s += ss_ + " " + exit[s_cur][j] + " "; //s += exit[s_cur][j] + " "; s_cur = s_new; cout << "str="; cin >> str; } cout << "stroka=" << s << endl; cout << " \n To continue - print yes" << endl; cin >> y; } while (y == "yes"); } int main() { char f[100] = "mili.txt"; ifstream fin; ofstream fout; mili m; m.obrobka(); m.fragment_clases_1ekv(); m.vuvod(); m.fragment_clases_ekv(); //m.New_f_nu(); m.vivod_New_f_nu(); //m.del(); m.obrobka_(); //m.new_vuvod(); system("pause"); return 0; }