fork(1) download
  1. #include <cmath>
  2. #include <iomanip>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const double PI = atan(1.0) * 4.0;
  8.  
  9. bool foo(const double a, const double b, const double g) {
  10. return a <= b ? (b - a <= PI && a <= g && g <= b) || (b - a > PI && (b <= g || g <= a)) : (a - b <= PI && b <= g && g <= a) || (a - b > PI && (a <= g || g <= b));
  11. }
  12.  
  13. bool bar(const double l, const double r, const double g) {
  14. return l <= g && g <= r || l <= g && r < l || g <= r && r < l;
  15. }
  16.  
  17. int main() {
  18. cout << boolalpha << "Case 1 Pass: " << bar(PI / 4.0, 3.0 * PI / 4.0, PI / 2.0) << ' ' << foo(PI / 4.0, 3.0 * PI / 4.0, PI / 2.0) << ' ' << foo(3.0 * PI / 4.0, PI / 4.0, PI / 2.0) << endl;
  19. cout << "Case 1 Fail: " << bar(PI / 4.0, 3.0 * PI / 4.0, PI) << ' ' << foo(PI / 4.0, 3.0 * PI / 4.0, PI) << ' ' << foo(3.0 * PI / 4.0, PI / 4.0, PI) << endl;
  20. cout << "Case 2 Pass: " << bar(7.0 * PI / 4.0, PI / 2.0, PI / 4.0) << ' ' << foo(7.0 * PI / 4.0, PI / 2.0, PI / 4.0) << ' ' << foo(PI / 2.0, 7.0 * PI / 4.0, PI / 4.0) << endl;
  21. cout << "Case 2 Fail: " << bar(7.0 * PI / 4.0, PI / 2.0, PI) << ' ' << foo(7.0 * PI / 4.0, PI / 2.0, PI) << ' ' << foo(PI / 2.0, 7.0 * PI / 4.0, PI) << endl;
  22. cout << "Case 3 Pass: " << bar(3.0 * PI / 2.0, PI / 4.0, 7.0 * PI / 4.0) << ' ' << foo(3.0 * PI / 2.0, PI / 4.0, 7.0 * PI / 4.0) << ' ' << foo(3.0 * PI / 2.0, PI / 4.0, 7.0 * PI / 4.0) << endl;
  23. cout << "Case 3 Fail: " << bar(3.0 * PI / 2.0, PI / 4.0, PI) << ' ' << foo(3.0 * PI / 2.0, PI / 4.0, PI) << ' ' << foo(3.0 * PI / 2.0, PI / 4.0, PI) << endl;
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Case 1 Pass: true true true
Case 1 Fail: false false false
Case 2 Pass: true true true
Case 2 Fail: false false false
Case 3 Pass: true true true
Case 3 Fail: false false false