Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <stack>
- # include <algorithm>
- using namespace std;
- int main()
- {
- vector <int> stack;
- vector<int>::iterator it;
- int rebs, ver;
- ifstream file("C:\\Users\\kalin\\Desktop\\test.txt");
- file >> ver;
- file >> rebs;
- int **smezh = new int*[rebs];
- for (int i = 0; i < rebs; i++)
- {
- smezh[i] = new int[rebs];
- }
- for (int i = 0; i < rebs; i++)
- for (int j = 0; j < rebs; j++)
- smezh[i][j] = 0;
- int sm, cm;
- for (int i = 0; i < rebs; i++)
- {
- for (int j = 0; j < rebs; j++)
- {
- file >> sm;
- file >> cm;
- smezh[sm-1][cm-1] = 1;
- cout << smezh[i][j] << " ";
- }
- cout << endl;
- }
- int vertst, verten;
- cout << "Input first top:" << endl;
- cin >> vertst;
- cout << "Input final top:" << endl;
- cin >> verten;
- int i = vertst - 1;
- rebs--;
- int b;
- do {
- int dach = 0;
- int j = 0;
- while (smezh[i][j] != 1&&j<=rebs)
- {
- if(j==rebs)
- {
- if (!stack.empty()) {
- stack.pop_back();
- i=b;
- }
- dach++;
- }
- j++;
- }
- if (dach == 0) {
- smezh[i][j] = 0;
- smezh[j][i] = 0;
- stack.insert(stack.end(), i + 1);
- for (it = stack.end() - 1; it != stack.end(); ++it) {
- cout << *it;
- }
- }
- cout << endl;
- /*for (int k = 0; k < rebs+1; k++)
- {
- for (int l = 0; l < rebs+1; l++)
- {
- cout << smezh[k][l] << " ";
- }
- cout << endl;
- }*/
- cout << endl;
- if (dach == 0)
- {
- b = i;
- }
- if (dach == 0) {
- i = j;
- }
- if (dach == 1)
- {
- b = i - 1;
- }
- } while (!stack.empty());
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement