Advertisement
annie_02

dr2_zad2-analog1sem

Dec 5th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | Source Code | 0 0
  1. int main()
  2. {
  3.  
  4.     double x, y;
  5.     cin >> x >> y;
  6.     bool is_in_square, is_on_square;
  7.  
  8.     if (x > -4 && x < 4 && y > -4 && y < 4)
  9.     {
  10.         is_in_square = 1;
  11.     }
  12.     else
  13.     {
  14.         is_in_square = 0;
  15.     }
  16.  
  17.     bool is_in_big_circle = x * x + y * y - 16 < DBL_EPSILON;
  18.     bool is_in_medium_left_circle = (x + 2) * (x + 2) + y * y - 4 < DBL_EPSILON;
  19.     bool is_in_medium_right_circle = (x - 2) * (x - 2) + y * y - 4 < DBL_EPSILON;
  20.     bool is_in_small_left_circle = (x + 2) * (x + 2) + y * y - 1 < DBL_EPSILON;
  21.     bool is_in_small_right_circle = (x - 2) * (x - 2) + y * y - 1 < DBL_EPSILON;
  22.  
  23.  
  24.     bool is_on_big_circle = x * x + y * y == 16;
  25.     bool is_on_medium_left_circle = (x + 2) * (x + 2) + y * y == 4 && y > 0;
  26.     bool is_on_medium_right_circle = (x - 2) * (x - 2) + y * y == 4 && y < 0;
  27.     bool is_on_small_left_circle = (x + 2) * (x + 2) + y * y == 1;
  28.     bool is_on_small_right_circle = (x - 2) * (x - 2) + y * y == 1;
  29.  
  30.     if (x == -4 || x == 4 || y == 4 || y == -4)
  31.     {
  32.         is_on_square = 1;
  33.     }
  34.     else
  35.     {
  36.         is_on_square = 0;
  37.     }
  38.    
  39.     //////////////////////////////////////////////////////////////////////////////////////////////////////
  40.  
  41.     if (is_on_square == 1 || is_on_big_circle == 1 || is_on_medium_left_circle == 1 || is_on_medium_right_circle == 1 || is_on_small_left_circle == 1 || is_on_small_right_circle == 1)
  42.     {
  43.         cout << "Undefined";
  44.     }
  45.     else
  46.     {
  47.         if (is_in_square == 1)
  48.         {
  49.             if (is_in_big_circle == 1)
  50.             {
  51.                 if (y > 0 && (is_in_medium_left_circle == 0 || is_in_small_left_circle == 1) && is_in_small_right_circle == 0)
  52.                 {
  53.  
  54.                     cout << "White";
  55.                 }
  56.                 else if (y > 0 && (is_in_medium_left_circle == 1 || is_in_small_left_circle == 0) && is_in_small_right_circle == 1)
  57.                 {
  58.                     cout << "Black";
  59.  
  60.                 }
  61.                 else if (y < 0 && (is_in_medium_right_circle == 0 || is_in_small_right_circle == 1) && is_in_small_left_circle == 0)
  62.                 {
  63.  
  64.                     cout << "Black";
  65.                 }
  66.                 else if (y < 0 && (is_in_medium_right_circle == 1 || is_in_small_right_circle == 0) && is_in_small_left_circle == 1)
  67.                 {
  68.                     cout << "White";
  69.  
  70.                 }
  71.             }
  72.             else
  73.             {
  74.                 cout << "White";
  75.             }
  76.         }
  77.         else
  78.         {
  79.             cout << "Outside";
  80.         }
  81.     }
  82.     return main();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement