Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class Fraction {
- private:
- long int x, y;
- public:
- Fraction(long int x = 0, long int y = 1) {
- this->x = x;
- this->y = y;
- }
- Fraction operator+ (Fraction other) {
- return Fraction(x * other.y + y * other.x, y * other.y);
- }
- Fraction operator- (Fraction other) {
- return Fraction(x * other.y - y * other.x, y * other.y);
- }
- Fraction operator* (Fraction other) {
- return Fraction(x * other.x, y * other.y);
- }
- Fraction operator/ (Fraction other) {
- return Fraction(x * other.y, y * other.x);
- }
- Fraction operator+ (long int z) {
- return Fraction(x + y * z, y);
- }
- Fraction operator- () {
- return Fraction(x = -x, y);
- }
- bool operator== (Fraction other) {
- if (x * other.y == other.x * y)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- bool operator< (Fraction other) {
- if (x * other.y < other.x * y)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- bool operator> (Fraction other) {
- if (x * other.y > other.x * y)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- friend istream& operator>>(istream& in, Fraction& a);
- friend ostream& operator<<(ostream& on, Fraction& a);
- };
- template <class T>
- class Array {
- private:
- int len;
- T* data;
- public:
- Array(int len = 0) {
- this->len = len;
- data = new T[len];
- }
- Array(const Array& other) {
- len = other.len;
- data = new T[len];
- for (int i = 0; i < len; i++) {
- data[i] = other.data[i];
- }
- }
- ~Array() { delete[] data; };
- T& operator[](int index) {
- index %= len;
- if (index < 0)
- {
- index = len + index;
- }
- return data[index];
- }
- T operator[](int index) const {
- index %= len;
- if (index < 0)
- {
- index = len + index;
- }
- return data[index];
- }
- Array& operator=(const Array& other) {
- delete[] data;
- len = other.len;
- data = new T[len];
- for (int i = 0; i < len; i++) {
- data[i] = other.data[i];
- }
- return *this;
- }
- Array operator() (int l, int r) {
- Array b(r - l - 1);
- cout << r - l - 1 << endl;
- for (int i = 0; i < r - l - 1; i++)
- {
- b[i] = data[i + l + 1];
- }
- return b;
- }
- int size() {
- return len;
- }
- T& array_max() {
- int max = 0;
- for (int i = 1; i < len; i++)
- {
- if (data[max] < data[i] )
- {
- max = i;
- }
- }
- return data[max];
- }
- };
- istream& operator>>(istream& in, Fraction& a) {
- char tmp;
- in >> a.x >> tmp >> a.y;
- return in;
- }
- ostream& operator<<(ostream& on, Fraction& a) {
- on << a.x << "/" << a.y;
- return on;
- }
- template <class T>
- istream& operator>>(istream& in, Array <T>& a) {
- for (int i = 0; i < a.size(); i++) {
- in >> a[i];
- }
- return in;
- }
- template <class T>
- ostream& operator<<(ostream& on, Array<T>& a) {
- for (int i = 0; i < a.size(); i++) {
- on << a[i] << ' ';
- }
- on << endl;
- return on;
- }
- int main() {
- int cntint, cntchar, cntFraction;
- cin >> cntint;
- Array<int> a(cntint);
- cin >> a;
- cin >> cntchar;
- Array <char> b(cntchar);
- cin >> b;
- cin >> cntFraction;
- Array<Fraction> c(cntFraction);
- cin >> c;
- cout << a.array_max() << endl;
- cout << b.array_max() << endl;
- cout << c.array_max() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement