SHARE
TWEET

Untitled

a guest Dec 14th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. void set(int m[][4], int i, int j, int v)
  5. {
  6.     m[i][j] = v;
  7.     m[j][i] = v;
  8. }
  9.  
  10. int main()
  11. {
  12.  
  13.     const int n = 4;
  14.  
  15.     int graph[n][n];
  16.     memset(graph, -1, n * n * sizeof(int));
  17.    
  18.     std::string cities[] = { "Pordenone", "Udine", "Gorizia", "Trieste" };
  19.  
  20.     set(graph, 0, 1, 50);
  21.     set(graph, 1, 2, 40);
  22.     set(graph, 1, 3, 80);
  23.     set(graph, 2, 3, 20);
  24.  
  25.     for (int i = 0; i < n; ++i)
  26.         for (int j = 0; j < n; ++j)
  27.             if (i != j)
  28.                 std::cout << (
  29.                     graph[i][j] != -1
  30.                         ? cities[i] + " -> " + cities[j] + " : " + std::to_string(graph[i][j]) + "\n"
  31.                         : "");
  32.  
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top