SHARE
TWEET

Untitled

a guest May 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. int b[20][20];
  9. int parcurs[20];
  10. int found = 0, add = 0;
  11. char *oras[] = {
  12.     "Neamt", "Iasi", "Vaslui", "Urziceni", "Harsova",
  13.     "Eforie", "Bucuresti", "Giurgiu", "Pitesti",
  14.     "Fagaras", "Craiova", "Drobeta","Mehadia","Lugoj", "Timisoara", "Arad",
  15.     "Zerind", "Oradea", "Sibiu", "Ramnicu valcea", "Lugoj",
  16. };
  17. int br = 0;
  18. void adancime(int x, int y) {
  19.     cout << "[" << x << "," << y << "]";
  20.     add++;
  21.     cout << "\n " << add<<"\n";
  22.  
  23.  
  24.     if (x == y) {
  25.         cout << "\nnr. de localitati distanta: " << add
  26.             << "\n orase din drum:";
  27.         parcurs[add - 1] = x;
  28.         for (int j = 0;j <= add;j++)
  29.             cout << oras[parcurs[j]] << " ";
  30.         cout << "\n";
  31.     }
  32.     for (int i = 0;i < 20;i++) {
  33.         cout << "." << i << ".";
  34.         parcurs[add-1] = x;
  35.         for (int j = 0;j < add-1;j++) {
  36.             if (parcurs[j] == i) {
  37.                 cout << "{" << i << "," << j << "}";
  38.                 br = 1;
  39.                 break;
  40.             }
  41.         }
  42.         if (br == 1) {
  43.             br = 0;
  44.             cout << ";";
  45.             continue;
  46.         }
  47.         cout << "[" << i << "]\n";
  48.         if (b[x][i] == 1) {
  49.             adancime(i,y);
  50.         }
  51.     }
  52.     add--;
  53.     cout << "\n " << add << " ---\n";
  54. }
  55.  
  56. void main() {
  57.     for (int i = 0;i < 20;i++)
  58.         for (int j = 0;j < 20;j++)
  59.             b[i][j] = 0;
  60.     b[0][1] = 1;
  61.     b[1][0] = 1;
  62.     b[1][2] = 1;
  63.     b[2][1] = 1;
  64.     b[2][3] = 1;
  65.     b[3][2] = 1;
  66.     b[3][4] = 1;
  67.     b[4][3] = 1;
  68.     b[4][5] = 1;
  69.     b[5][4] = 1;
  70.     b[3][6] = 1;
  71.     b[6][3] = 1;
  72.     b[6][7] = 1;
  73.     b[7][6] = 1;
  74.     b[6][8] = 1;
  75.     b[8][6] = 1;
  76.     b[6][9] = 1;
  77.     b[9][6] = 1;
  78.     b[8][10] = 1;
  79.     b[10][8] = 1;
  80.     b[8][19] = 1;
  81.     b[10][19] = 1;
  82.     b[19][10] = 1;
  83.     b[9][18] = 1;
  84.     b[18][9] = 1;
  85.     b[19][18] = 1;
  86.     b[18][19] = 1;
  87.     b[18][17] = 1;
  88.     b[17][18] = 1;
  89.     b[18][15] = 1;
  90.     b[15][18] = 1;
  91.     b[15][16] = 1;
  92.     b[16][15] = 1;
  93.     b[16][17] = 1;
  94.     b[17][16] = 1;
  95.     b[15][14] = 1;
  96.     b[14][15] = 1;
  97.     b[14][13] = 1;
  98.     b[13][14] = 1;
  99.     b[13][12] = 1;
  100.     b[12][11] = 1;
  101.     b[11][12] = 1;
  102.     b[11][10] = 1;
  103.     b[10][11] = 1;
  104.  
  105.     for (int i = 0;i < 20;i++) {
  106.         for (int j = 0;j < 20;j++) {
  107.             cout << b[i][j] << " ";
  108.         }
  109.         cout << endl;
  110.     }
  111.     int n;
  112.     cout << "\nnume plecare\n";
  113.     cin >> n;
  114.     cout << oras[n] << "\nare drum catre\n" << endl;
  115.     for (int i = 0;i < 20;i++) {
  116.         if (b[i][n] == 1 || b[n][i] == 1) {
  117.             cout << oras[i] << endl;
  118.         }
  119.     }
  120.     int m;
  121.     cout << "\noras sosire\n";
  122.     cin >> m;
  123.     cout << "\nruta este:\n";
  124.     for (int i = 0;i < 20;i++)
  125.         parcurs[i] = -1;
  126.  
  127.     adancime(n, m);
  128.  
  129.  
  130.     getch();
  131. }
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