# 13505 - String Calculator(class) 2 >author: Utin ###### tags: `class` --- ## Brief See the code below ## Solution 0 ```cpp= #include <iostream> #include "function.h" std::string arr = "0123456789abcdefghijklmnopqrstuvwxyz"; String_Calculator::String_Calculator(const std::string str) : s(str) {} String_Calculator& String_Calculator::Add(const string add) { this->s += add; return *this; } String_Calculator& String_Calculator::Subtract(const string sub) { size_t pos = this->s.find(sub, 0); if (pos == string::npos) this->s = "error"; else this->s.erase(pos, sub.size()); return *this; } String_Calculator& String_Calculator::Shift(const string shift) { for (int i = 0; i < shift.size(); i++) { if (!isdigit(shift[i])) { this->s = "error"; return *this; } } int shift_bits = stoi(shift); shift_bits %= arr.size(); for (int i = 0; i < this->s.size(); i++) { for (int j = 0; j < arr.size(); j++) { if (this->s[i] == arr[j]) { int idx = j + shift_bits; if (idx >= arr.size()) idx -= arr.size(); this->s[i] = arr[idx]; break; } } } return *this; } void String_Calculator::output() const { cout << s << '\n'; } // Utin ``` ## Reference