Advertisement
pperf

capitrals _ unqualified

Jul 23rd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6.  
  7. void DumpVector(const vector<string>& s){
  8. for (const auto& item:s){
  9. cout<<item <<endl;
  10. }
  11. }
  12. void DumpVectorOfMaps(const vector<map<char,int>>& s){
  13. for (const auto& item:s){
  14. for (const auto& c:item){
  15. cout<<c.first << " "<<c.second<<endl;
  16. }
  17. cout <<endl;
  18. }
  19. }
  20.  
  21. void DumpMap(const map<char,int>& c){
  22. for (const auto& item:c){
  23. cout<<item.first << " "<<item.second<<endl;
  24. }
  25. }
  26.  
  27. void DumpMapString(const map<string,string>& c){
  28. for (const auto& item:c){
  29. cout<<item.first << " "<<item.second<<" ";
  30. }
  31. cout<<endl;
  32. }
  33.  
  34. string CountChars(const vector<string>& words){
  35. map<char,int> result;
  36. vector<map<char,int>> v_result;
  37. string tf="NO";
  38.  
  39. for (const string& item:words){
  40. for (auto ch:item){
  41. result[ch]++;
  42. }
  43. v_result.push_back(result);
  44. result.clear();
  45. }
  46.  
  47. // DumpVectorOfMaps(v_result);
  48.  
  49. if (v_result[0]==v_result[1]){
  50. tf="YES";
  51. } else {
  52. tf="NO";
  53. }
  54.  
  55. v_result.erase(v_result.begin(),v_result.end());
  56. return tf;
  57. }
  58.  
  59. int main() {
  60. int i=0;
  61. cin>>i;
  62. string country, capital, new_capital, old_capital, old_country_name, new_country_name="";
  63. string operation;
  64. map<string,string> countries;
  65. map<string,int> capitals;
  66.  
  67. while (i>0){
  68.  
  69. cin>>operation;
  70. if (operation=="CHANGE_CAPITAL"){
  71. //CHANGE_CAPITAL
  72. cin>>country;
  73. cin>>new_capital;
  74.  
  75. if (countries.count(country)==0){
  76. cout<<"Introduce new country "<< country <<" with capital "<< new_capital << endl;
  77. countries[country]= new_capital;
  78. }
  79.  
  80. else if (countries[country]==new_capital){
  81. cout<<"Country "<< country <<" hasn't changed its capital" << endl;
  82. }
  83.  
  84. else if (countries[country]!=new_capital && countries.count(country)!=0){
  85. cout<<"Country "<<country<<" has changed its capital from "<<countries[country]<<" to "<<new_capital<< endl;
  86. countries[country]=new_capital;
  87. }
  88.  
  89. }
  90. if (operation=="RENAME"){
  91. //RENAME
  92. cin>>old_country_name;
  93. cin>>new_country_name;
  94. //DumpMapString(countries);
  95.  
  96. if (countries.count(old_country_name)==0 || countries.count(new_country_name)!=0|| old_country_name==new_country_name){
  97. //check
  98. cout<<"Incorrect rename, skip"<< endl;
  99. // DumpMapString(countries);
  100. }
  101.  
  102. if (countries.count(old_country_name)!=0 && old_country_name!=new_country_name)
  103. {
  104. cout<<"Country "<<old_country_name<<" with capital "<<countries[old_country_name]<<" has been renamed to "<<new_country_name<< endl;
  105. countries[new_country_name]=countries[old_country_name];
  106. countries.erase(old_country_name);
  107. }
  108.  
  109. }
  110.  
  111. if (operation=="ABOUT"){
  112. // ABOUT
  113. cin>>country;
  114. if(countries.count(country)==0){
  115. cout<<"Country "<<country<<" doesn't exist"<< endl;
  116. }
  117. else{
  118. cout<<"Country "<<country<<" has capital "<<countries[country]<< endl;
  119. }
  120. }
  121. if (operation=="DUMP"){
  122. //DUMP
  123. if(countries.empty()){
  124. cout<<"There are no countries in the world"<< endl;
  125. }
  126. else
  127. {
  128. for (const auto & item:countries){
  129. cout << item.first << "/" << item.second << " " ;
  130. }
  131. cout<<endl;
  132. }
  133. //DumpMapString(countries);
  134. }
  135. --i;
  136. }
  137.  
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement