Advertisement
syasinaeg

Чугунова Полина: "Дроби: сравнение с вещественным числом"

Mar 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4. #include <string>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. class  Fraction {
  12. private:
  13.     long long x, y;
  14. public:
  15.  
  16.     void normalize() {
  17.         if (y < 0) {
  18.             x = x*(-1);
  19.             y = y*(-1);
  20.         }
  21.         //сокращение дробей по евклиду
  22.         long long a = abs(x), b = abs(y);
  23.         while (a != b) {
  24.             if (a > b) a -= b;
  25.             else b -= a;
  26.         }
  27.         x /= a;
  28.         y /= a;
  29.     }
  30.  
  31.     Fraction(long long x = 0, long long y = 1) {
  32.         this->x = x;
  33.         this->y = y;
  34.     }
  35.  
  36.     friend bool operator <(double a, Fraction &s) {
  37.         if (a < ((double) s.x)/ s.y) {
  38.             return true;
  39.         }
  40.         else return false;
  41.     }
  42.  
  43.     void read() {
  44.         string a;
  45.         string b = "/";
  46.         int i;
  47.         cin >> a;
  48.         i = a.find(b);
  49.         x = stoi(a.substr(0, i));
  50.         y = stoi(a.substr(i + 1));
  51.     }
  52. };
  53.  
  54. int main() {
  55.     double z;
  56.     cin >> z;
  57.     Fraction a;
  58.     a.read();
  59.     if (z < a) cout << "YES";
  60.     else cout << "NO";
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement