Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <fstream>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9. int n;
  10.  
  11. bool *visited = new bool[n];
  12. vector <int> answer;
  13. int way = 0;
  14. int i, j;
  15. int pass = 0;
  16. int **x;
  17.  
  18. void check(int st, int k);
  19.  
  20. void main()
  21. {
  22. ifstream in("input.txt");
  23. if (in.is_open())
  24. {
  25. int count = 0;
  26. int temp;
  27. while (!in.eof())
  28. {
  29. in >> temp;
  30. count++;
  31. }
  32. in.seekg(0, ios::beg);
  33. in.clear();
  34. int count_space = 0;
  35. char symbol;
  36. while (!in.eof())
  37. {
  38. in.get(symbol);
  39. if (symbol == ' ')
  40. count_space++;
  41. if (symbol == '\n')
  42. break;
  43. }
  44. in.seekg(0, ios::beg);
  45. in.clear();
  46. n = count / (count_space + 1);
  47. int m = count_space + 1;
  48. x = new int*[n];
  49. for (int i = 0; i<n; i++)
  50. x[i] = new int[m];
  51. for (int i = 0; i < n; i++)
  52. for (int j = 0; j < m; j++)
  53. in >> x[i][j];
  54. for (int i = 0; i < n; i++)
  55. {
  56. for (int j = 0; j < m; j++)
  57. cout << x[i][j] << "\t";
  58. cout << "\n";
  59. }
  60. in.close();
  61. }
  62. else
  63. {
  64. cout << "File did not find";
  65. }
  66. int k;
  67. int start;
  68. i = 0;
  69.  
  70. while (i < n)
  71. {
  72. visited[i] = false;
  73. cout << endl;
  74. i++;
  75. }
  76. cout << n << endl;
  77. cout << "Enter starting vertex: ";
  78. cin >> start;
  79. cout << "Enter length: ";
  80. cin >> k;
  81. cout << "ways: " << endl;
  82. check(start - 1, k);
  83. cout << "searche " << way;
  84. delete[]visited;
  85. getch();
  86. }
  87. void check(int st, int k)
  88. {
  89. int i;
  90. visited[st] = true;
  91. answer.push_back(st + 1);
  92. for (i = 0; i < n; i++)
  93. {
  94. if ((x[st][i] == 1) && (visited[i] == false))
  95. {
  96. if ((pass + 1) != k)
  97. {
  98. pass++;
  99. check(i, k);
  100. visited[i] = false;
  101. }
  102.  
  103. else
  104. {
  105. answer.push_back(i + 1);
  106. for (int j = 0; j < answer.size(); j++)
  107. {
  108. cout << answer[j] << " ";
  109. }
  110. way = way + 1;
  111. answer.erase(answer.end() - 1);
  112. cout << endl;
  113. }
  114. }
  115. }
  116. if (answer.size() > 1)
  117. {
  118. answer.erase(answer.end() - 1);
  119. }
  120. pass--;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement