#include #include #include using namespace std; template class SuperFraction { public: int a, b; SuperFraction(); SuperFraction(T a, T b); void print(); }; template SuperFraction::SuperFraction() { this->a = 0; this->b = 1; } template SuperFraction::SuperFraction(T a, T b) { this->a = a; this->b = b; if (this->a == 0 && this->b == 0) return; if (this->a >= this->b) this->a %= this->b; if (this->a == 0) this->b = 1; int divisor = gcd(this->a, this->b); this->a /= divisor; this->b /= divisor; } template void SuperFraction::print() { cout << this->a << "/" << this->b << endl; } template class SuperExtraMegaWowOfFractions { private: vector> data; public: bool isEmpty(); void append(SuperFraction fraction); void exclude(SuperFraction fraction); SuperFraction sum(); }; template bool SuperExtraMegaWowOfFractions::isEmpty() { return this->data.size() == 0; } template void SuperExtraMegaWowOfFractions::append(SuperFraction fraction) { for (int index = 0; index < this->data.size(); index++) if (this->data[index].a == fraction.a && this->data[index].b == fraction.b) return; this->data.push_back(fraction); } template void SuperExtraMegaWowOfFractions::exclude(SuperFraction fraction) { for (int index = 0; index < this->data.size(); index++) { if (this->data[index].a == fraction.a && this->data[index].b == fraction.b) { this->data.erase(this->data.begin() + index); break; } } } template SuperFraction SuperExtraMegaWowOfFractions::sum() { if (isEmpty()) return SuperFraction(0, 0); int numerator = 0; int denominator = 1; for (int index = 0; index < this->data.size(); index++) { numerator = numerator * this->data[index].b + this->data[index].a * denominator; denominator *= this->data[index].b; } return SuperFraction(numerator, denominator); }