Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Fraction {
- private:
- vector<unsigned char> wholePart, fractionPart;
- bool sign;
- public:
- Fraction() {
- wholePart = {};
- fractionPart = {};
- sign = false;
- }
- Fraction(vector<unsigned char> &_w, vector<unsigned char> &_f, unsigned char &_s) {
- reverse(_w.begin(), _w.end());
- wholePart = _w;
- fractionPart = _f;
- if (_s == '-')
- sign = true;
- else {
- sign = false;
- }
- }
- friend bool operator==(const Fraction &a, const Fraction &b) {
- return a.fractionPart == b.fractionPart && a.wholePart == b.wholePart && a.sign == b.sign;
- }
- friend bool operator!=(const Fraction &a, const Fraction &b) {
- return !(a == b);
- }
- friend bool operator<(const Fraction &a, const Fraction &b) {
- if (a.sign && !b.sign) {
- return true;
- }
- if (!a.sign && b.sign) {
- return false;
- }
- if (a.wholePart.size() != b.wholePart.size()) {
- if (a.sign) {
- return !(a.wholePart.size() < b.wholePart.size());
- } else {
- return a.wholePart.size() < b.wholePart.size();
- }
- } else if (a.wholePart != b.wholePart) {
- int _size = a.wholePart.size();
- for (int i = _size - 1; i >= 0; --i) {
- if (a.wholePart[i] != b.wholePart[i]) {
- if (a.sign) {
- return !(a.wholePart[i] < b.wholePart[i]);
- } else {
- return a.wholePart[i] < b.wholePart[i];
- }
- }
- }
- } else {
- for (int i = 0; i < min(a.fractionPart.size(), b.fractionPart.size()); ++i) {
- if (a.fractionPart[i] != b.fractionPart[i]) {
- if (a.sign) {
- return !(a.fractionPart[i] < b.fractionPart[i]);
- } else {
- return a.fractionPart[i] < b.fractionPart[i];
- }
- }
- }
- if (a.sign) {
- return !(a.fractionPart.size() < b.fractionPart.size());
- } else {
- return a.fractionPart.size() < b.fractionPart.size();
- }
- }
- }
- friend bool operator>(const Fraction &a, const Fraction &b) {
- return !(a < b);
- }
- friend Fraction operator-(const Fraction &a, const Fraction &b) {
- }
- friend Fraction operator+(const Fraction &a, const Fraction &b) {
- }
- friend Fraction operator*(const Fraction &a, const Fraction &b) {
- }
- };
- int main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement