Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main(){
- int q;
- map<string, string> directory;
- cin >> q;
- for (int i = 0; i < q; ++i) {
- string operation_code;
- cin >> operation_code;
- if (operation_code == "CHANGE_CAPITAL") {
- string country, new_capital;
- cin >> country >> new_capital;
- if (directory.count(country) == 0) {
- directory[country] = new_capital;
- cout << "Introduce new country " << country << " with capital " << new_capital << endl;
- }else {
- if (new_capital == directory[country]) {
- cout << "Country " << country << " hasn't changed its capital" << endl;
- }else {
- cout << "Country " << country << " has changed its capital from " << directory[country] << " to " << new_capital << endl;
- directory[country] = new_capital;
- }
- }
- }else {
- if (operation_code == "RENAME") {
- string old_country_name, new_country_name;
- cin >> old_country_name >> new_country_name;
- if (old_country_name == new_country_name || directory.count(old_country_name) == 0 || directory.count(new_country_name) == 1) {
- cout << "Incorrect rename, skip" << endl;
- }else {
- cout << "Country " << old_country_name << " with capital " << directory[old_country_name] << " has been renamed to " << new_country_name << endl;
- directory[new_country_name] = directory[old_country_name];
- directory.erase(old_country_name);
- }
- }else {
- if (operation_code == "ABOUT") {
- string country;
- cin >> country;
- if (directory.count(country) == 0) {
- cout << "Country " << country << " doesn't exist" << endl;
- }else {
- cout << "Country " << country << " has capital " << directory[country] << endl;
- }
- }else {
- if (operation_code == "DUMP") {
- if (directory.size() == 0) {
- cout << "There are no countries in the world" << endl;
- }else {
- for (auto item : directory) {
- cout << item.first << "/" << item.second << " ";
- }
- }
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement