Advertisement
werandrew

Untitled

Apr 4th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include<vector>
  4. using namespace std;
  5.  
  6. class Fraction{
  7. long long x, y;
  8. char c;
  9. public:
  10. Fraction(long long _x=0, long long _y=1):x(_x), y(_y){}
  11. Fraction operator+(Fraction & n2){
  12.         long long new_x =x*n2.y+y*n2.x;
  13.         long long new_y=y*n2.y;
  14.         Fraction new_num(new_x, new_y);
  15.  
  16.         return new_num;
  17. }
  18. Fraction operator+(long long);
  19. friend Fraction operator + (long long, const Fraction &);
  20. friend istream & operator>>(istream &, Fraction &);
  21. friend ostream & operator<<(ostream &, const Fraction &);
  22. void show();
  23. void read();
  24. };
  25.  
  26. istream & operator>>(istream  & inp, Fraction & f){
  27.         char c;
  28.         inp >> f.x>>c>>f.y;
  29.         return inp;
  30. }
  31.  
  32. ostream & operator<<(ostream  & out, const Fraction & f){
  33.         out << f.x<<"/"<<f.y;
  34.         return out;
  35. }
  36.  
  37. Fraction operator + (long long n, const Fraction & f){
  38.         return (f.x + n*f.y, f.y);
  39. }
  40. Fraction Fraction::operator+(long long n){
  41.         return Fraction(this->x+n*this->y, this->y);
  42. }
  43. void Fraction::read(){cin >> x >> c >> y;}
  44. void Fraction::show(){cout<<x<<"/"<<y;}
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. void print(vector<Fraction> v, vector<Fraction> vy){
  53.     if(v.size()<vy.size()){
  54.         cout<<"YES";
  55.     }
  56.     else{
  57.         cout<<"NO";
  58.     }
  59. }
  60.  
  61.  
  62.  
  63. void print(vector<int> v, vector<int> vy){
  64.     if(v.size()<vy.size()){
  65.         cout<<"YES";
  66.     }
  67.     else{
  68.         cout<<"NO";
  69.     }
  70. }
  71.  
  72.  
  73.  
  74.  
  75. void print(vector<char> v, vector<char> vy){
  76.  
  77.     if(v.size()<vy.size()){
  78.         cout<<"YES";
  79.     }
  80.     else{
  81.         cout<<"NO";
  82.     }
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. template<typename A>
  95. void print(A v1, A v2) {
  96.     if(v1>v2){
  97. cout << v1;
  98.     }
  99. else{
  100.  cout << v2;
  101. }
  102. }
  103. int main() {
  104.     Fraction f;
  105.     string choice;
  106.     cin >> choice;
  107.     if (choice == "INT") {
  108. int n, t;
  109. int ny, ty;
  110. vector<int> a;
  111. vector<int> ay;
  112. cin >> n;
  113. for (int i = 0; i < n; i++) {
  114. cin >> t;
  115. a.push_back(t);
  116. }
  117.  
  118. cin >> ny;
  119. for (int i = 0; i < ny; i++) {
  120. cin >> ty;
  121. ay.push_back(ty);
  122. }
  123. print(a, ay);
  124.     }
  125.     else if (choice == "CHAR") {
  126.         int yx;char yy;
  127. int yv;char yw;
  128. vector<char> yvv;
  129. vector<char> yww;
  130. cin >> yx;
  131. for (int i = 0; i < yx; i++) {
  132. cin >> yy;
  133. yvv.push_back(yy);
  134. }
  135.  
  136. cin >> yv;
  137. for (int i = 0; i < yv; i++) {
  138. cin >> yw;
  139. yww.push_back(yw);
  140. }
  141. print(yvv, yww);
  142.     }
  143.  
  144. else if (choice == "FRACTION") {
  145.         int x;Fraction y;
  146. int v;Fraction w;
  147. vector<Fraction> vv;
  148. vector<Fraction> ww;
  149. cin >> x;
  150. for (int i = 0; i < x; i++) {
  151. cin >> y;
  152. vv.push_back(y);
  153. }
  154.  
  155. cin >> v;
  156. for (int i = 0; i < v; i++) {
  157. cin >> w;
  158. ww.push_back(w);
  159. }
  160. print(vv, ww);
  161. }
  162.     return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement