Advertisement
kutuzzzov

Урок 4

Jul 13th, 2023
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string_view>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // clang-format off
  9.  
  10. const int NUM_PLANETS = 8;
  11. const string_view PLANETS[] = {
  12.     "Mercury"sv, "Venus"sv, "Earth"sv,
  13.     "Mars"sv, "Jupiter"sv, "Saturn"sv,
  14.     "Uranus"sv, "Neptune"sv,
  15. };
  16.  
  17. // clang-format on
  18.  
  19. bool IsPlanet(string_view name) {
  20.     for (int i = 0; i < NUM_PLANETS; ++i) {
  21.         if (PLANETS[i] == name) {
  22.             return true;
  23.         }
  24.     }
  25.     return false;
  26. }
  27.  
  28. void Test(string_view name) {
  29.     cout << name << " is " << (IsPlanet(name) ? ""sv : "NOT "sv)
  30.         << "a planet"sv << endl;
  31. }
  32.  
  33. int main() {
  34.     string name;
  35.     getline(cin, name);
  36.     Test(name);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement