Untitled
unknown
plain_text
a year ago
1.2 kB
34
Indexable
#include <bits/stdc++.h>
using namespace std;
class StringFunction {
public:
virtual string Edit(string str1, string str2) = 0;
};
class AppendFunction : public StringFunction {
public:
string Edit(string str1, string str2) override {
return str1 + str2;
}
};
class ReverseAppendFunction : public StringFunction {
public:
string Edit(string str1, string str2) override {
return str2 + str1;
}
};
/*
str1 + str1 + str2
*/
class CustomAppendFunction : public StringFunction {
public:
string Edit(string str1, string str2) override {
return str1 + str1 + str2;
}
};
class TextEditor {
public:
string Format(string str1, string str2, StringFunction& func) {
return func.Edit(str1, str2);
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
TextEditor editor;
string str1, str2;
cin >> str1 >> str2;
AppendFunction append_function;
cout << editor.Format(str1, str2, append_function) << endl;
ReverseAppendFunction rev_append_function;
cout << editor.Format(str1, str2, rev_append_function) << endl;
CustomAppendFunction custom_function;
cout << editor.Format(str1, str2, custom_function) << endl;
return 0;
}
Editor is loading...
Leave a Comment