Advertisement
qberik

Untitled

Nov 20th, 2022
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. #define TABLE vector<vector<int>>
  6.  
  7. #define ERROR_MESSAGE "pizdos oshibka"
  8.  
  9.  
  10. TABLE hsdjifhozdsh( TABLE in ){
  11. TABLE smej;
  12. int n = in.size(); // количество вершин
  13. int m = in[0].size(); // количество путей
  14.  
  15. // запоняем всё нулями
  16. vector<int> tmp;
  17. for( int i = 0; i < n; i++ )
  18. tmp.push_back(0);
  19. for( int i = 0; i < n; i++ )
  20. smej.push_back(tmp);
  21.  
  22. vector<int> temp;
  23. vector<int> temp_pos;
  24. for( int j = 0; j < m; j++ ){
  25.  
  26. temp.clear();
  27. temp_pos.clear();
  28. for( int i = 0; i < n; i++ ){
  29. if( in[i][j] != 0 ){
  30. temp.push_back(in[i][j]);
  31. temp_pos.push_back(i);
  32. }
  33. }
  34.  
  35. if( temp.size() == 2 ){
  36. int a = temp[0];
  37. int b = temp[1];
  38. int a_pos = temp_pos[0];
  39. int b_pos = temp_pos[1];
  40. // первое число всегда больше
  41. if( b > a ){
  42. a = temp[1];
  43. b = temp[0];
  44. a_pos = temp_pos[1];
  45. b_pos = temp_pos[0];
  46. }
  47. if( a == b && a == 1 ){ // a = 1 && b = 1
  48. smej[a_pos][b_pos] = 1;
  49. smej[b_pos][a_pos] = 1;
  50. }else if( a == 1 && b == -1 ){ // a = 1 && b = -1
  51. smej[a_pos][b_pos] = 1;
  52. }else{
  53. cout << ERROR_MESSAGE << endl;
  54. }
  55. }else{
  56. cout << ERROR_MESSAGE << endl;
  57. }
  58. }
  59.  
  60.  
  61.  
  62. return smej;
  63. }
  64.  
  65. int main(){
  66.  
  67. TABLE incendent =
  68. {
  69. { 1, 0, 0, 0, 0, 1, 0, 1},
  70. { 0, 1, 0, 1, 0,-1, 0, 0},
  71. {-1, 0, 1,-1, 1, 0, 0, 0},
  72. { 0, 0, 0, 0,-1, 0, 1, 0},
  73. { 0,-1,-1, 0, 0, 0, 1, 1},
  74. };
  75.  
  76. TABLE result = hsdjifhozdsh(incendent);
  77.  
  78. for( auto line : result ){
  79. for( auto elem : line ){
  80. cout << elem << ' ';
  81. } cout << endl;
  82. }
  83.  
  84. return 0;
  85.  
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement