Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int q;
  9. cin >> q;
  10.  
  11. map<string, string> country_to_capital;
  12.  
  13. for (int i = 0; i < q; ++i) {
  14. string operation_code;
  15. cin >> operation_code;
  16.  
  17. if (operation_code == "CHANGE_CAPITAL") {
  18.  
  19. string country, new_capital;
  20. cin >> country >> new_capital;
  21. if (country_to_capital.count(country) == 0) {
  22. cout << "Introduce new country " << country << " with capital " << new_capital << endl;
  23. } else {
  24. const string& old_capital = country_to_capital[country];
  25. if (old_capital == new_capital) {
  26. cout << "Country " << country << " hasn't changed its capital" << endl;
  27. } else {
  28. cout << "Country " << country << " has changed its capital from " << old_capital << " to " << new_capital << endl;
  29. }
  30. }
  31. country_to_capital[country] = new_capital;
  32.  
  33. } else if (operation_code == "RENAME") {
  34.  
  35. string old_country_name, new_country_name;
  36. cin >> old_country_name >> new_country_name;
  37. if (old_country_name == new_country_name || country_to_capital.count(old_country_name) == 0 || country_to_capital.count(new_country_name) == 1) {
  38. cout << "Incorrect rename, skip" << endl;
  39. } else {
  40. cout << "Country " << old_country_name << " with capital " << country_to_capital[old_country_name] <<
  41. " has been renamed to " << new_country_name << endl;
  42. country_to_capital[new_country_name] = country_to_capital[old_country_name];
  43. country_to_capital.erase(old_country_name);
  44. }
  45.  
  46. } else if (operation_code == "ABOUT") {
  47.  
  48. string country;
  49. cin >> country;
  50. if (country_to_capital.count(country) == 0) {
  51. cout << "Country " << country << " doesn't exist" << endl;
  52. } else {
  53. cout << "Country " << country << " has capital " << country_to_capital[country] << endl;
  54. }
  55.  
  56. } else if (operation_code == "DUMP") {
  57.  
  58. if (country_to_capital.empty()) {
  59. cout << "There are no countries in the world" << endl;
  60. } else {
  61. for (const auto& country_item : country_to_capital) {
  62. cout << country_item.first << "/" << country_item.second << " ";
  63. }
  64. cout << endl;
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement