Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- void DumpVector(const vector<string>& s){
- for (const auto& item:s){
- cout<<item <<endl;
- }
- }
- void DumpVectorOfMaps(const vector<map<char,int>>& s){
- for (const auto& item:s){
- for (const auto& c:item){
- cout<<c.first << " "<<c.second<<endl;
- }
- cout <<endl;
- }
- }
- void DumpMap(const map<char,int>& c){
- for (const auto& item:c){
- cout<<item.first << " "<<item.second<<endl;
- }
- }
- void DumpMapString(const map<string,string>& c){
- for (const auto& item:c){
- cout<<item.first << " "<<item.second<<" ";
- }
- cout<<endl;
- }
- string CountChars(const vector<string>& words){
- map<char,int> result;
- vector<map<char,int>> v_result;
- string tf="NO";
- for (const string& item:words){
- for (auto ch:item){
- result[ch]++;
- }
- v_result.push_back(result);
- result.clear();
- }
- // DumpVectorOfMaps(v_result);
- if (v_result[0]==v_result[1]){
- tf="YES";
- } else {
- tf="NO";
- }
- v_result.erase(v_result.begin(),v_result.end());
- return tf;
- }
- int main() {
- int i=0;
- cin>>i;
- string country, capital, new_capital, old_capital, old_country_name, new_country_name="";
- string operation;
- map<string,string> countries;
- map<string,int> capitals;
- while (i>0){
- cin>>operation;
- if (operation=="CHANGE_CAPITAL"){
- //CHANGE_CAPITAL
- cin>>country;
- cin>>new_capital;
- if (countries.count(country)==0){
- cout<<"Introduce new country "<< country <<" with capital "<< new_capital << endl;
- countries[country]= new_capital;
- }
- else if (countries[country]==new_capital){
- cout<<"Country "<< country <<" hasn't changed its capital" << endl;
- }
- else if (countries[country]!=new_capital && countries.count(country)!=0){
- cout<<"Country "<<country<<" has changed its capital from "<<countries[country]<<" to "<<new_capital<< endl;
- countries[country]=new_capital;
- }
- }
- if (operation=="RENAME"){
- //RENAME
- cin>>old_country_name;
- cin>>new_country_name;
- //DumpMapString(countries);
- if (countries.count(old_country_name)==0 || countries.count(new_country_name)!=0|| old_country_name==new_country_name){
- //check
- cout<<"Incorrect rename, skip"<< endl;
- // DumpMapString(countries);
- }
- if (countries.count(old_country_name)!=0 && old_country_name!=new_country_name)
- {
- cout<<"Country "<<old_country_name<<" with capital "<<countries[old_country_name]<<" has been renamed to "<<new_country_name<< endl;
- countries[new_country_name]=countries[old_country_name];
- countries.erase(old_country_name);
- }
- }
- if (operation=="ABOUT"){
- // ABOUT
- cin>>country;
- if(countries.count(country)==0){
- cout<<"Country "<<country<<" doesn't exist"<< endl;
- }
- else{
- cout<<"Country "<<country<<" has capital "<<countries[country]<< endl;
- }
- }
- if (operation=="DUMP"){
- //DUMP
- if(countries.empty()){
- cout<<"There are no countries in the world"<< endl;
- }
- else
- {
- for (const auto & item:countries){
- cout << item.first << "/" << item.second << " " ;
- }
- cout<<endl;
- }
- //DumpMapString(countries);
- }
- --i;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement