Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <iomanip>
- #include <set>
- #include <algorithm>
- #include <deque>
- using namespace std;
- deque<char> move(deque<char> p, int u)
- {
- if ((u == 0) || (p.size() == 1)) {
- return p;
- }
- else if (u < 0)
- {
- for (int i = 0; i < -u; i++)
- {
- char temp = p.back();
- p.pop_back();
- p.push_front(temp);
- }
- }
- else
- {
- for (int i = 0; i < u; i++)
- {
- char temp = p.front();
- p.pop_front();
- p.push_back(temp);
- }
- }
- return p;
- }
- class Barrel {
- int cnt; // Количество шаров в барабане
- deque<char> balls; // Дин. массив из cnt символов (буквы на шарах в порядке по часовой стрелке)
- public:
- Barrel(string str = NULL) { // Заполнить барабан шарами-буквами из строчки str
- for (int i = 0; i < str.size(); i++) {
- this->balls.push_back(str[i]);
- }
- }
- ~Barrel() {
- deque<char>().swap(this->balls);
- }
- int count() { // Получить количество шаров в барабане
- return this->balls.size();
- }
- void clockwise(int x) { // Сдвинуть барабан на x шаров по часовой стрелке
- this->balls = move(this->balls, x);
- }
- void countercw(int x) { // Сдвинуть барабан на x шаров против часовой стрелки
- this->balls = move(this->balls, x);
- }
- char extract() { // Извлечь первый шар из барабана
- char c = this->balls[0];
- this->balls.pop_front();
- return c;
- }
- deque<char> getBalls() {
- return this->balls;
- }
- };
- int main() {
- int n;
- string start;
- cin >> start;
- Barrel b(start);
- cin >> n;
- while (n--) {
- int shift;
- cin >> shift;
- if (shift < 0) {
- b.clockwise(shift);
- }
- else if (shift > 0) {
- b.countercw(shift);
- }
- /*for (char i : b.getBalls()) {
- cout << i << ' ';
- }
- cout << endl;*/
- cout << b.extract();
- /*for (char i : b.getBalls()) {
- cout << i << ' ';
- }
- cout << endl;*/
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement