template<class T> void reverseLinkedList(list<T>& originList){ list<T> resList; for(list<T>::iterator iter=originList.begin();iter!=originList.end();++iter){ T tempT = *iter; resList.push_front(tempT); } originList.assign(resList.begin(),resList.end()); return; }
void parse_cmd_line(const deque<wstring>& params, list<wstring>& source_dirs, list<wstring>& include_dirs) { source_dirs.assign(1, wstring()); for (auto param = params.cbegin(); param != params.cend(); ++param) { if (substr_match(*param, 0, L"-I")) { wstring inc_dir = param->substr(2); CHECK_CMD(!inc_dir.empty()); fix_slashes(inc_dir); include_dirs.push_back(inc_dir); } else { wstring src_dir = *param; fix_slashes(src_dir); source_dirs.push_back(src_dir); } } }
/* * === FUNCTION ====================================================================== * Name: shuffle_population * Description: simulates random mixing for susceptible population * ===================================================================================== */ void shuffle_population(list<person> & population) { vector<person> temp_container(population.begin(), population.end()); random_shuffle(temp_container.begin(), temp_container.end()); population.assign(temp_container.begin(), temp_container.end()); }
int main() { int T; freopen("in.txt", "r", stdin); scanf("%d", &T); while (T --) { scanf("%d%s", &n, s); int len = strlen(s); mlist.clear(); tmplist.clear(); it = mlist.begin(); mode = INSERT; nowlen = 0; for (int i = 0; i < len; ++ i) { //printf("the op is ===%c---\n", s[i]); if (s[i] >= 'a' && s[i] <= 'z') { if (state == START) state = NOTNG; if (mlist.size() == n && (mode == INSERT || mode == OVERWT && it == mlist.end())) continue; mlist.insert(it, s[i]); nowlen++; if (mode == OVERWT) { if (it != mlist.end()) { it = mlist.erase(it); } } } else if (s[i] == 'L') { if (it != mlist.begin()) { it--; pos--; nowlen--; } } else if (s[i] == 'R') { if (it != mlist.end()) { it ++; pos++; nowlen++; } } else if (s[i] == 'S') { mode ^= 1; if (state == START) state = NOTNG; } else if (s[i] == 'D') { if (state == NOTNG) { if (it != mlist.end()) { it = mlist.erase(it); } } else { state = NOTNG; if (pos > 0) { it = tmplist.erase(preit, it); nowlen -= pos; } else { it = tmplist.erase(it, preit); } } } else if (s[i] == 'B') { if (state == START) state = NOTNG; if (it != mlist.begin()) { nowlen--; /*if (it != mlist.end()) { printf("123456789\n"); }*/ it --; //printf("BBBB-%c\n", *it); it = mlist.erase(it); /*if (it != mlist.end()) { printf("123456798\n"); }*/ } } else if (s[i] == 'C') { if (state == NOTNG) { pos = 0; state = START; preit = it;//printf("---%c\n", *preit); } else if (state == START) { state = NOTNG; tmplist.clear(); if (pos > 0) { tmplist.assign(preit, it); } else { tmplist.assign(it, preit); } } } else if (s[i] == 'V') { if (state == START) state = NOTNG; tt.clear(); tt.assign(tmplist.begin(), tmplist.end()); if (mode == INSERT && mlist.size() + tmplist.size() <= n) { mlist.splice(it, tt); nowlen += tmplist.size(); } else if (mode == OVERWT && nowlen + tmplist.size() <= n) { //int lenlen = tmplist.size(); //printf("%c%d\n", *it, tmplist.size()); mlist.splice(it, tt); nowlen += tmplist.size(); //printf("%c%d\n", *it, tmplist.size()); for (int i = 0; i < tmplist.size(); ++ i) { if (it == mlist.end()) break; //printf("%c\n", *it); it = mlist.erase(it); } } } /*for (list<char>::iterator i = mlist.begin(); i != mlist.end(); ++ i) { printf("%c", *i); } printf("\n");*/ } if (mlist.size() > 0) { for (list<char>::iterator i = mlist.begin(); i != mlist.end(); ++ i) { printf("%c", *i); } } else { printf("NOTHING"); } printf("\n"); } return 0; }