Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <stack>
  6. # include <algorithm>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. vector <int> stack;
  12. vector<int>::iterator it;
  13.  
  14.  
  15. int rebs, ver;
  16. ifstream file("C:\\Users\\kalin\\Desktop\\test.txt");
  17. file >> ver;
  18. file >> rebs;
  19. int **smezh = new int*[rebs];
  20. for (int i = 0; i < rebs; i++)
  21. {
  22. smezh[i] = new int[rebs];
  23. }
  24. for (int i = 0; i < rebs; i++)
  25. for (int j = 0; j < rebs; j++)
  26. smezh[i][j] = 0;
  27.  
  28. int sm, cm;
  29. for (int i = 0; i < rebs; i++)
  30. {
  31. for (int j = 0; j < rebs; j++)
  32. {
  33. file >> sm;
  34. file >> cm;
  35. smezh[sm-1][cm-1] = 1;
  36. cout << smezh[i][j] << " ";
  37. }
  38. cout << endl;
  39. }
  40. int vertst, verten;
  41. cout << "Input first top:" << endl;
  42. cin >> vertst;
  43. cout << "Input final top:" << endl;
  44. cin >> verten;
  45. int i = vertst - 1;
  46. rebs--;
  47. int b;
  48. do {
  49. int dach = 0;
  50. int j = 0;
  51. while (smezh[i][j] != 1&&j<=rebs)
  52. {
  53. if(j==rebs)
  54. {
  55. if (!stack.empty()) {
  56. stack.pop_back();
  57. i=b;
  58. }
  59. dach++;
  60. }
  61. j++;
  62. }
  63. if (dach == 0) {
  64. smezh[i][j] = 0;
  65. smezh[j][i] = 0;
  66. stack.insert(stack.end(), i + 1);
  67. for (it = stack.end() - 1; it != stack.end(); ++it) {
  68. cout << *it;
  69. }
  70. }
  71. cout << endl;
  72. /*for (int k = 0; k < rebs+1; k++)
  73. {
  74. for (int l = 0; l < rebs+1; l++)
  75. {
  76. cout << smezh[k][l] << " ";
  77. }
  78. cout << endl;
  79. }*/
  80. cout << endl;
  81. if (dach == 0)
  82. {
  83. b = i;
  84. }
  85. if (dach == 0) {
  86. i = j;
  87. }
  88. if (dach == 1)
  89. {
  90. b = i - 1;
  91. }
  92. } while (!stack.empty());
  93. cout << endl;
  94.  
  95.  
  96.  
  97. system("pause");
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement