Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class String {
- private:
- char* str;
- int len;
- public:
- String(int len = 0) {
- this->len = len;
- str = new char[len];
- }
- String(const String& other) {
- len = other.len;
- str = new char[other.len];
- for (int i = 0; i < len; i++) {
- str[i] = other.str[i];
- }
- }
- String(const char* str) {
- int counter = 0;
- while (str[counter] != 0) counter++;
- len = counter;
- this->str = new char[len];
- for (int i = 0; i < len; i++) {
- this->str[i] = str[i];
- }
- }
- char& operator[](int index) {
- return str[index];
- }
- char operator[](int index) const {
- return str[index];
- }
- ~String() {
- delete[] str;
- }
- String& operator=(String& other) {
- delete[] str;
- len = other.len;
- str = new char[other.len];
- for (int i = 0; i < len; i++) {
- str[i] = other.str[i];
- }
- return *this;
- }
- String& operator+(String& other) {
- char* str_new = new char[len];
- for (int i = 0; i < len; i++)
- {
- str_new[i] = str[i];
- }
- str = new char[len + other.len];
- for (int i = 0; i < len; i++) {
- str[i] = str_new[i];
- }
- for (int i = 0; i < other.len; i++) {
- str[i+len] = other[i];
- }
- len += other.size();
- return *this;
- }
- String& operator*(int x) {
- char* str_new = new char[len * x];
- for (int i = 0; i < len * x; i++)
- {
- str_new[i] = str[i % len];
- }
- str = new char[len * x];
- str = str_new;
- len *= x;
- return *this;
- }
- int size() const {
- return len;
- }
- friend istream& operator>>(istream& in, String& a);
- friend ostream& operator<<(ostream& on, String& a);
- };
- istream& operator>>(istream& in, String& a) {
- int buffer_size = 1000000;
- char* buffer = new char[buffer_size];
- in.getline(buffer, buffer_size);
- a.str = buffer;
- a.len = strlen(buffer);
- return in;
- }
- ostream& operator<<(ostream& on, String& a) {
- for (int i = 0; i < a.size(); i++) {
- on << a[i];
- }
- on << endl;
- return on;
- }
- int main() {
- String z;
- int tmp;
- cin >> z;
- cin >> tmp;
- cout << z * tmp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement