werandrew

Untitled

Apr 2nd, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 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.    for (int i = 0; i < v.size()/2; i++){
  46.             int tmp = v[i];
  47.         v[i] = v[v.size()-1-i];
  48.         v[v.size()-1-i] = tmp;
  49.     }
  50.     for (int i = 0; i < v.size(); i++)
  51.     cout <<v[i]<<" ";
  52. }
  53.  
  54. void printy(vector<char> v){
  55.    for (int i = 0; i < v.size()/2; i++){
  56.             char tmp = v[i];
  57.         v[i] = v[v.size()-1-i];
  58.         v[v.size()-1-i] = tmp;
  59.     }
  60.     for (int i = 0; i < v.size(); i++)
  61.     cout <<v[i]<<" ";
  62. }
  63.  
  64. void printyz(vector<Fraction> v){
  65.    for (int i = 0; i < v.size()/2; i++){
  66.             Fraction tmp = v[i];
  67.         v[i] = v[v.size()-1-i];
  68.         v[v.size()-1-i] = tmp;
  69.     }
  70.     for (int i = 0; i < v.size(); i++)
  71.     cout <<v[i]<<" ";
  72. }
  73.  
  74. int main() {
  75.     Fraction f;
  76. int n, t;
  77. vector<int> a;
  78. cin >> n;
  79. for (int i = 0; i < n; i++) {
  80. cin >> t;
  81. a.push_back(t);
  82. }
  83.  
  84. int ny;char ty;
  85. vector<char> arr;
  86. cin >> ny;
  87. for (int i = 0; i < ny; i++) {
  88. cin >> ty;
  89. arr.push_back(ty);
  90. }
  91.  
  92. int nyz;
  93. Fraction tyz;
  94. vector<Fraction> arrd;
  95. cin >> nyz;
  96. for (int i = 0; i < nyz; i++) {
  97. cin >> tyz;
  98. arrd.push_back(tyz);
  99. }
  100.  
  101. cout<<n<<endl;
  102. print(a);cout<<endl;
  103. cout<<ny<<endl;
  104. printy(arr);cout<<endl;
  105. cout<<nyz<<endl;
  106. printyz(arrd);
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment