Advertisement
werandrew

Untitled

Apr 2nd, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. using namespace std;
  4. class Fraction{
  5. long long x, y;
  6. char c;
  7. public:
  8. Fraction(long long _x=0, long long _y=1):x(_x), y(_y){}
  9. Fraction operator+(Fraction & n2){
  10.         long long new_x =x*n2.y+y*n2.x;
  11.         long long new_y=y*n2.y;
  12.         Fraction new_num(new_x, new_y);
  13.  
  14.         return new_num;
  15. }
  16. Fraction operator+(long long);
  17. friend Fraction operator + (long long, const Fraction &);
  18. friend istream & operator>>(istream &, Fraction &);
  19. friend ostream & operator<<(ostream &, const Fraction &);
  20. void show();
  21. void read();
  22. };
  23.  
  24. istream & operator>>(istream  & inp, Fraction & f){
  25.         char c;
  26.         inp >> f.x>>c>>f.y;
  27.         return inp;
  28. }
  29.  
  30. ostream & operator<<(ostream  & out, const Fraction & f){
  31.         out << f.x<<"/"<<f.y;
  32.         return out;
  33. }
  34.  
  35. Fraction operator + (long long n, const Fraction & f){
  36.         return (f.x + n*f.y, f.y);
  37. }
  38. Fraction Fraction::operator+(long long n){
  39.         return Fraction(this->x+n*this->y, this->y);
  40. }
  41. void Fraction::read(){cin >> x >> c >> y;}
  42. void Fraction::show(){cout<<x<<"/"<<y;}
  43.  
  44. void print(vector<int> v){
  45.          int max = v[0];
  46.     for (int i = 0; i < v.size(); ++i) {
  47.         if (v[i] > max) {
  48.             max = v[i];
  49.         }
  50.     }
  51. cout << max << " ";
  52.  
  53. }
  54.  
  55. void printy(vector<char> v){
  56.            char max = v[0];
  57.     for (int i = 0; i < v.size(); ++i) {
  58.         if (v[i] > max) {
  59.             max = v[i];
  60.         }
  61.     }
  62. cout << max << " ";
  63.  
  64. }
  65.  
  66. void printyz(vector<Fraction> v){
  67.        /*    Fraction max = v[0];
  68.     for (int i = 0; i < v.size(); ++i) {
  69.         if (v[i] > max) {
  70.             max = v[i];
  71.         }
  72. cout << max << " ";
  73. }
  74.  
  75. */
  76. }
  77. int main() {
  78.     Fraction f;
  79. int n, t;
  80. vector<int> a;
  81. cin >> n;
  82. for (int i = 0; i < n; i++) {
  83. cin >> t;
  84. a.push_back(t);
  85. }
  86.  
  87. int ny;char ty;
  88. vector<char> arr;
  89. cin >> ny;
  90. for (int i = 0; i < ny; i++) {
  91. cin >> ty;
  92. arr.push_back(ty);
  93. }
  94.  
  95. int nyz;
  96. Fraction tyz;
  97. vector<Fraction> arrd;
  98. cin >> nyz;
  99. for (int i = 0; i < nyz; i++) {
  100. cin >> tyz;
  101. arrd.push_back(tyz);
  102. }
  103.  
  104. print(a);cout<<endl;
  105. printy(arr);cout<<endl;
  106. printyz(arrd);
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement