Skip to content

Instantly share code, notes, and snippets.

@balamark
Last active October 31, 2017 16:20
Show Gist options
  • Save balamark/24d983db5a34243c2d6a07939e075feb to your computer and use it in GitHub Desktop.
Save balamark/24d983db5a34243c2d6a07939e075feb to your computer and use it in GitHub Desktop.
SRM419 div1 250
string getText(vector<string> commands, vector<int> time) {
string ret = "";
for(int i=commands.size()-1; i>=0;){
istringstream iss(commands[i]);
vector<string> tokens {istream_iterator<string>{iss}, istream_iterator<string>{}};
if(tokens[0]=="undo"){
int ustep = stoi(tokens[1]);
int cur_time = time[i];
i-=1;
while(i>=0 && cur_time - time[i] <= ustep){
i-=1; //ignore both undo and type
}
}
else{//"type"
ret.insert(0, tokens[1]);
--i;
}
}
return ret;
}
//petr
public string getText(string[] commands, int[] time) {
string[] stateBefore = new string[commands.Length + 1];
stateBefore[0] = "";
for (int i = 0; i < commands.Length; ++i)
{
string[] p = commands[i].Split(' ');
if (p[0] == "type")
{
stateBefore[i + 1] = stateBefore[i] + p[1];
}
else
{
int j = i;
int len = int.Parse(p[1]);
while (j > 0 && time[j - 1] + len >= time[i])
--j;
stateBefore[i + 1] = stateBefore[j];
}
}
return stateBefore[commands.Length];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment