shushus

Спринт 14. Неожиданные последствия неопределенного поведения.

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