Paste will expire never.
- // Очно-заочный кружок
- // Занятие №9. Дополнительные олимпиадные задачи
- // Задача C. Переключение между окнами
- // ibelyaev: 31Oct2011
- // http://cppalgo.blogspot.com/2011/04/blog-post.html
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <string.h>
- #include <cmath>
- #include <queue>
- #include <vector>
- #include <map>
- #include <stdlib.h> // for exit(0)
- #include <stack>
- #include <list>
- #include <ctime>
- #include <set>
- using namespace std;
- list<string> mas;
- list<string>::iterator curIt = mas.begin();
- int plus_amount(const string &s) {
- int amount = 0;
- for (int i=0;i<s.size();++i)
- amount += s[i] == '+' ? 1 : 0;
- return amount;
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- ios::sync_with_stdio(false);
- int n;
- cin>>n;
- string command, name;
- getline(cin,command);
- for (int i=0;i<n;++i) {
- getline(cin,command);
- if (command[0] == 'R') {
- name = command.substr(4,command.size() - 4);
- mas.push_back(name);
- }
- else {
- int amount = plus_amount(command);
- curIt = --mas.end();
- for (int j=0;j<amount;++j) {
- if (curIt == mas.begin())
- curIt = mas.end();
- curIt--;
- }
- name = *curIt;
- mas.erase(curIt);
- mas.push_back(name);
- }
- cout<<mas.back()<<endl;
- }
- return 0;
- }
Editing is locked.