Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <stack>
  6. #include <set>
  7. #include <stdlib.h>
  8. #include <algorithm>
  9. #include <stack>
  10.  
  11. using namespace std;
  12.  
  13. void Reverse_Sort(vector<pair<int, int>>& arr, int l, int r) {
  14. int i = l, j = r;
  15. int obj = arr[(l + r) / 2].second;
  16. /* partition */
  17. while (i <= j) {
  18. while (arr[i].second > obj)
  19. i++;
  20. while (arr[j].second < obj)
  21. j--;
  22. if (i <= j) {
  23. swap(arr[i], arr[j]);
  24. i++;
  25. j--;
  26. }
  27. };
  28. /* recursion */
  29. if (l < j)
  30. Reverse_Sort(arr, l, j);
  31.  
  32. if (i < r)
  33. Reverse_Sort(arr, i, r);
  34. }
  35.  
  36.  
  37.  
  38. static int a = 1;
  39.  
  40. vector<pair<int, int>> post(12);
  41.  
  42. vector<bool> used(12);
  43.  
  44. void dfs(vector<vector<bool>>& relations,int i){
  45. bool count = false;
  46. for(int j=0; j<relations[i].size(); ++j){
  47. if(relations[i][j]){
  48. count = true;
  49. if (!used[j]){
  50. used[j] = true;
  51. ++a;
  52. dfs(relations, j);
  53. }
  54. }
  55. }
  56. /*if(!count)
  57. dfs(relations, ++i);*/
  58. ++a;
  59. post[i].first=i+1;
  60. post[i].second=a;
  61. }
  62.  
  63.  
  64. vector<vector<std::string>> getList(vector<string>& names, vector<vector<bool>>& relations)
  65. {
  66. int n = 12;
  67. dfs(relations, 0);
  68. Reverse_Sort(post, 0, post.size()-1);
  69. for(int i=0; i<post.size(); ++i)
  70. cout<<post[i].first<< " " << post[i].second<<endl;
  71.  
  72. vector<vector<string>> myvector;
  73. int count = 0;
  74. for(int i = 0; i < post.size(); ++i ){
  75. for(int j = 0; j < relations[post[i].first].size(); ++j){
  76. if(!relations[i][j]) {
  77. myvector[count].push_back(names[i]);
  78. }
  79. }
  80. }
  81. int a=3223;
  82. }
  83. int main()
  84. {
  85. vector<string> names = vector<string>();
  86. vector<vector<bool>> relations;
  87. int startIndex;
  88.  
  89. ifstream fin;
  90. fin.open("input.txt");
  91. if (fin.is_open())
  92. {
  93. string str = "";
  94. getline(fin, str);
  95.  
  96. while (str != "#")
  97. {
  98. names.emplace_back(str.substr(str.find(' ') + 1));
  99. getline(fin, str);
  100. }
  101.  
  102. relations = vector<vector<bool>>(names.size());
  103.  
  104. for (int i = 0; i < names.size(); i++)
  105. {
  106. relations[i] = vector<bool>(names.size());
  107. for (int j = 0; j < names.size(); j++)
  108. relations[i][j] = false;
  109. }
  110.  
  111. getline(fin, str);
  112.  
  113. while (fin)
  114. {
  115. int a = stoi(str.substr(0, str.find(' '))) - 1;
  116. int b = stoi(str.substr(str.find(' '))) - 1;
  117. relations[a][b] = true;
  118. getline(fin, str);
  119. }
  120.  
  121. fin.close();
  122. }
  123.  
  124. vector<vector<string>> res = getList(names, relations);
  125.  
  126. /*fstream fout;
  127. fout.open("output.txt", ios::out);
  128. for (int i = 0; i < res.size(); i++)
  129. {
  130. for (int j = 0; j < res[i].size(); j++)
  131. fout « res[i][j] « "\n";
  132. fout « "\n";
  133. }
  134. fout.close();*/
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement