Advertisement
MaximCherchuk

Test

Jan 22nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef unsigned short us;
  6.  
  7. void check_connectivity(us* indexTriples, int* connectivityOut, int all_verticies, pair<us, us> p, int index, int shift) {
  8.     if(p.first > p.second) {
  9.         swap(p.first, p.second);
  10.     }
  11.     for(int j = 0; j < all_verticies; j += 3) {
  12.         if(j == index) continue;
  13.         int first = indexTriples[j];
  14.         int second = indexTriples[j + 1];
  15.         int third = indexTriples[j + 2];
  16.         if((p.first == first && p.second == second) || (p.first == second && p.second == first)) {
  17.             connectivityOut[index + shift] = j;
  18.             break;
  19.         }
  20.         if((p.first == second && p.second == third) || (p.first == third && p.second == second)) {
  21.             connectivityOut[index + shift] = j + 1;
  22.             break;
  23.         }
  24.         if((p.first == third && p.second == first) || (p.first == first && p.second == third)) {
  25.             connectivityOut[index + shift] = j + 2;
  26.         }
  27.     }
  28. }
  29.  
  30. void findConnectivity(us* indexTriples, int T, int* connectivityOut) {
  31.     const int all_verticies = 3 * T;
  32.     std::fill(connectivityOut, connectivityOut + all_verticies, -1);
  33.     for(int i = 0; i < all_verticies; i += 3) {
  34.         pair<us, us> p1 = make_pair(indexTriples[i], indexTriples[i + 1]);
  35.         pair<us, us> p2 = make_pair(indexTriples[i + 1], indexTriples[i + 2]);
  36.         pair<us, us> p3 = make_pair(indexTriples[i + 2], indexTriples[i]);
  37.  
  38.         check_connectivity(indexTriples, connectivityOut, all_verticies, p1, i, 0);
  39.         check_connectivity(indexTriples, connectivityOut, all_verticies, p2, i, 1);
  40.         check_connectivity(indexTriples, connectivityOut, all_verticies, p3, i, 2);
  41.     }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47.     int T = 3;
  48.     int* connectivityOut = new int[3 * T];
  49.     us *input = new us[9] {0,2,7,1,7,2,6,2,0};
  50.     findConnectivity(input, 3, connectivityOut);
  51.     for(int i = 0; i < 3 * T; ++i) {
  52.         cout << connectivityOut[i] + 1 << ' ';
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement