fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int distance[5][5] = {
  8. {0, 343, 294, 346, 348},
  9. {343, 0, 573, 659, 442},
  10. {294, 573, 0, 99, 258},
  11. {346, 659, 99, 0, 357},
  12. {348, 442, 258, 357, 0}
  13. };
  14.  
  15. string cityA, cityB;
  16. int indexA = -1, indexB = -1;
  17.  
  18. cout << "Available cities:\n";
  19. cout << "Warszawa, Gdansk, Krakow, NowySacz, Wroclaw\n";
  20. cout << "\nEnter first city: ";
  21. cin >> cityA;
  22.  
  23. cout << "Enter second city: ";
  24. cin >> cityB;
  25.  
  26. if (cityA == "Warszawa") indexA = 0;
  27. else if (cityA == "Gdansk") indexA = 1;
  28. else if (cityA == "Krakow") indexA = 2;
  29. else if (cityA == "NowySacz") indexA = 3;
  30. else if (cityA == "Wroclaw") indexA = 4;
  31.  
  32. if (cityB == "Warszawa") indexB = 0;
  33. else if (cityB == "Gdansk") indexB = 1;
  34. else if (cityB == "Krakow") indexB = 2;
  35. else if (cityB == "NowySacz") indexB = 3;
  36. else if (cityB == "Wroclaw") indexB = 4;
  37.  
  38. if (indexA == -1 || indexB == -1) {
  39. cout << "Unknown city name!\n";
  40. } else {
  41. cout << "Distance between " << cityA << " and " << cityB << " is " << distance[indexA][indexB] << " km\n";
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Available cities:
Warszawa, Gdansk, Krakow, NowySacz, Wroclaw

Enter first city: Enter second city: Unknown city name!