SRM 419 DV2 500
簡単なテキストエディタを想定して、それにundoを実装する問題。
#include <vector> #include <string> using namespace std; class Undo{ private: bool isType(string command){ string::size_type index = command.find("type"); if (index == string::npos){ return false; }else{ return true; } } string getChar(string command){ int size = command.size(); return command.substr(5, size); } int getInt(string command) { int size = command.size(); return atoi(command.substr(5, size).c_str()); } public: string getText(vector <string> commands, vector <int> time){ string tmp = ""; int size = commands.size(); int undoTime; for (int i = size - 1; i >= 0; i --){ bool flag = isType(commands[i]); //typeならTrue, undoならfalse if (!flag){ undoTime = time[i] - getInt(commands[i]); for (int j = 0; j < size; j ++){ if (undoTime <= time[j] && time[j] < time[i]){ time[j] = 0; } } } } for (int i = 0; i < size; i ++){ bool flag = isType(commands[i]); if (flag && time[i] != 0){ tmp += getChar(commands[i]); } } return tmp; } };