Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- #define TABLE vector<vector<int>>
- #define ERROR_MESSAGE "pizdos oshibka"
- TABLE hsdjifhozdsh( TABLE in ){
- TABLE smej;
- int n = in.size(); // количество вершин
- int m = in[0].size(); // количество путей
- // запоняем всё нулями
- vector<int> tmp;
- for( int i = 0; i < n; i++ )
- tmp.push_back(0);
- for( int i = 0; i < n; i++ )
- smej.push_back(tmp);
- vector<int> temp;
- vector<int> temp_pos;
- for( int j = 0; j < m; j++ ){
- temp.clear();
- temp_pos.clear();
- for( int i = 0; i < n; i++ ){
- if( in[i][j] != 0 ){
- temp.push_back(in[i][j]);
- temp_pos.push_back(i);
- }
- }
- if( temp.size() == 2 ){
- int a = temp[0];
- int b = temp[1];
- int a_pos = temp_pos[0];
- int b_pos = temp_pos[1];
- // первое число всегда больше
- if( b > a ){
- a = temp[1];
- b = temp[0];
- a_pos = temp_pos[1];
- b_pos = temp_pos[0];
- }
- if( a == b && a == 1 ){ // a = 1 && b = 1
- smej[a_pos][b_pos] = 1;
- smej[b_pos][a_pos] = 1;
- }else if( a == 1 && b == -1 ){ // a = 1 && b = -1
- smej[a_pos][b_pos] = 1;
- }else{
- cout << ERROR_MESSAGE << endl;
- }
- }else{
- cout << ERROR_MESSAGE << endl;
- }
- }
- return smej;
- }
- int main(){
- TABLE incendent =
- {
- { 1, 0, 0, 0, 0, 1, 0, 1},
- { 0, 1, 0, 1, 0,-1, 0, 0},
- {-1, 0, 1,-1, 1, 0, 0, 0},
- { 0, 0, 0, 0,-1, 0, 1, 0},
- { 0,-1,-1, 0, 0, 0, 1, 1},
- };
- TABLE result = hsdjifhozdsh(incendent);
- for( auto line : result ){
- for( auto elem : line ){
- cout << elem << ' ';
- } cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement