Advertisement
Trawka011

Untitled

Jan 19th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class String {
  6. private:
  7.     char* str;
  8.     int len;
  9. public:
  10.     String(int len = 0) {
  11.         this->len = len;
  12.         str = new char[len];
  13.     }
  14.     String(const String& other) {
  15.         len = other.len;
  16.         str = new char[other.len];
  17.         for (int i = 0; i < len; i++) {
  18.             str[i] = other.str[i];
  19.         }
  20.     }
  21.     String(const char* str) {
  22.         int counter = 0;
  23.         while (str[counter] != 0) counter++;
  24.         len = counter;
  25.         this->str = new char[len];
  26.         for (int i = 0; i < len; i++) {
  27.             this->str[i] = str[i];
  28.         }
  29.     }
  30.     char& operator[](int index) {
  31.         return str[index];
  32.     }
  33.     char operator[](int index) const {
  34.         return str[index];
  35.     }
  36.     ~String() {
  37.         delete[] str;
  38.     }
  39.     String& operator=(String& other) {
  40.         delete[] str;
  41.         len = other.len;
  42.         str = new char[other.len];
  43.         for (int i = 0; i < len; i++) {
  44.             str[i] = other.str[i];
  45.         }
  46.         return *this;
  47.     }
  48.     String& operator+(String& other) {
  49.         char* str_new = new char[len];
  50.         for (int i = 0; i < len; i++)
  51.         {
  52.             str_new[i] = str[i];
  53.         }
  54.         str = new char[len + other.len];
  55.         for (int i = 0; i < len; i++) {
  56.             str[i] = str_new[i];
  57.         }
  58.         for (int i = 0; i < other.len; i++) {
  59.             str[i+len] = other[i];
  60.         }
  61.         len += other.size();
  62.         for (int i = 0; i < len + other.len; i++)
  63.         {
  64.             if (i % 2 != 0)
  65.             {
  66.                 str[i] = '_';
  67.             }
  68.         }
  69.         return *this;
  70.     }
  71.     int size() const {
  72.         return len;
  73.     }
  74.     friend istream& operator>>(istream& in, String& a);
  75.     friend ostream& operator<<(ostream& on, String& a);
  76. };
  77. istream& operator>>(istream& in, String& a) {
  78.     int buffer_size = 1000000;
  79.     char* buffer = new char[buffer_size];
  80.     in.getline(buffer, buffer_size);
  81.     a.str = buffer;
  82.     a.len = strlen(buffer);
  83.     return in;
  84. }
  85.  
  86. ostream& operator<<(ostream& on, String& a) {
  87.     for (int i = 0; i < a.size(); i++) {
  88.         on << a[i];
  89.     }
  90.     on << endl;
  91.     return on;
  92. }
  93.  
  94. int main() {
  95.     String q,w,e,r,t,y;
  96.     int tmp;
  97.     cin >> q >> w >> e >> r >> t;
  98.     y = q + w + e + r + t;
  99.     cout << y;
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement