Advertisement
Spocoman

04. Foreign Languages

Nov 2nd, 2023
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string country;
  7.     getline(cin, country);
  8.  
  9.     string language;
  10.  
  11.     if (country == "England" || country == "USA") {
  12.         language = "English";
  13.     }
  14.     else if (country == "Spain" || country == "Argentina" || country == "Mexico") {
  15.         language = "Spanish";
  16.     }
  17.     else {
  18.         language = "unknown";
  19.     }
  20.  
  21.     cout << language << endl;
  22.     return 0;
  23. }
  24.  
  25. Решение с тернарен оператор:
  26.  
  27. #include <iostream>
  28.  
  29. using namespace std;
  30.  
  31. int main() {
  32.     string country;
  33.     getline(cin, country);
  34.  
  35.     string language =
  36.         country == "England" || country == "USA" ? "English" :
  37.         country == "Spain" || country == "Argentina" || country == "Mexico" ? "Spanish" : "unknown";
  38.  
  39.     cout << language << endl;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement