Advertisement
intsashka

ht01-4

Sep 18th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int
  4. main(void)
  5. {
  6.     enum
  7.     {
  8.         COEFFICIENT1 = 4,
  9.         TWO_ANSWER = 2
  10.     };
  11.     int a, b, c, ans = 0;
  12.     long long d;
  13.     double x1, x2, sqrt_d;
  14.  
  15.     scanf("%d%d%d", &a, &b, &c);
  16.     if(a && b && c)
  17.     {
  18.         d = b * 1LL * b - COEFFICIENT1 * 1LL * a * c;
  19.         if (d == 0) {
  20.             ans = 1;
  21.             x1 = (double) -b / (2 * a);
  22.         } else if (d > 0) {
  23.             ans = TWO_ANSWER;
  24.             sqrt_d = sqrt(d);
  25.             x1 = (-b - sqrt_d) / (2 * a);
  26.             x2 = (-b + sqrt_d) / (2 * a);
  27.         }
  28.     } else if (a && b) {
  29.         ans = TWO_ANSWER;
  30.         if(b < 0) {
  31.             x1 = 0;
  32.             x2 = (double) -b / a;
  33.         } else {
  34.             x1 = (double) -b / a;
  35.             x2 = 0;
  36.         }
  37.     } else if (a && c) {
  38.         if(-c * 1LL * a > 0) {
  39.             ans = TWO_ANSWER;
  40.             x1 = -sqrt((double) -c / a);
  41.             x2 = -x1;
  42.         }
  43.     } else if (a) {
  44.         ans = 1;
  45.         x1 = 0;
  46.     } else if (b && c) {
  47.         ans = 1;
  48.         x1 = (double) -b / c;
  49.     } else if (b) {
  50.         ans = 1;
  51.         x1 = 0;
  52.     } else if (c == 0) {
  53.         ans = -1;
  54.     }
  55.  
  56.  
  57.     printf("%d", ans);
  58.     if(ans > 0) {
  59.         printf(" %.10lf", x1);
  60.     }
  61.     if(ans > 1) {
  62.         printf(" %.10lf", x2);
  63.     }
  64.     printf("\n");
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement