Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class list {
- private:
- class node{
- char value;
- node *next;
- node *prev;
- public:
- node(char arg) {
- value = arg;
- next = NULL;
- prev = NULL;
- }
- void setnext(node *pol) {
- next = pol;
- }
- void setprev(node *pol) {
- prev = pol;
- }
- node* getnext() {
- return next;
- }
- node* getprev() {
- return prev;
- }
- void write() {
- cout << value;
- }
- };
- node* first;
- node* last;
- int x, y;
- char dir;
- public:
- list(int x, int y) {
- first = NULL;
- last = NULL;
- dir = '4';
- this->x = x;
- this->y = y;
- }
- void addfirst(char val) {
- node *one = new node(val);
- one->setnext(first);
- if (last == NULL)
- last = one;
- else
- first->setprev(one);
- first = one;
- }
- void addlast(char val) {
- node *inf = new node(val);
- inf->setprev(last);
- if (first == NULL)
- first = inf;
- else
- last->setnext(inf);
- last = inf;
- }
- void removefirst() {
- if (first == NULL)
- return;
- else if (first == last) {
- delete first;
- first = NULL;
- last = NULL;
- }
- else {
- first = first->getnext();
- delete first->getprev();
- first->setprev(NULL);
- }
- }
- void removelast() {
- if (last == NULL)return;
- else if (last == first) {
- delete last;
- last = NULL;
- first = NULL;
- }
- else {
- last = last->getprev();
- delete last->getnext();
- last->setnext(NULL);
- }
- }
- void write() {
- node *ptr = first;
- cout << x << ' ' << y << ' ';
- if (stillalive() == false) {
- cout << '#';
- }
- else {
- while (ptr != NULL) {
- ptr->write();
- ptr = ptr->getnext();
- }
- }
- cout << endl;
- }
- void move(char **tab, int width, int height) {
- if (tab[x - 1][y - 1] == '1' || tab[x - 1][y - 1] == '2' || tab[x - 1][y - 1] == '3' || tab[x - 1][y - 1] == '4') {
- dir = tab[x - 1][y - 1];
- }
- else if (tab[x - 1][y - 1] >= 'a' && tab[x - 1][y - 1] <= 'z') {
- addfirst(tab[x - 1][y - 1]);
- tab[x - 1][y - 1] -= 1;
- }
- else if (tab[x - 1][y - 1] >= 'A' && tab[x - 1][y - 1] <= 'Z') {
- addlast(tab[x - 1][y - 1] + ' ');
- tab[x - 1][y - 1] -= 1;
- }
- else if (tab[x - 1][y - 1] == 'a' - 1) {
- removefirst();
- }
- else if (tab[x - 1][y - 1] == 'A' - 1) {
- removelast();
- }
- }
- bool stillalive() {
- if (first == NULL) {
- return false;
- }
- else return true;
- }
- void nextmove(int height, int width) {
- if (dir == '1') {
- y--;
- if (y == 0) y = height;
- }
- if (dir == '2') {
- y++;
- if (y == height + 1) y = 1;
- }
- if (dir == '3') {
- x--;
- if (x == 0) x = width;
- }
- if (dir == '4') {
- x++;
- if (x == width + 1) x = 1;
- }
- }
- };
- int main()
- {
- int moves;
- int width, height, len;
- char uio;
- int x,y;
- cin >> width>>height>>moves;
- cin >> x >> y>>len;
- list l(x, y);
- for (int i = 0; i < len; i++) {
- cin >> uio;
- l.addlast(uio);
- }
- char **tab = new char*[height];
- for (int i = 0; i <height; i++) {
- tab[i] = new char[width];
- }
- for (int i = 0; i < height; i++) {
- for (int j = 0; j< width; j++) {
- cin >> tab[j][i];
- }
- }
- for (int i = 0; i < moves; i++) {
- l.move(tab, width, height);
- if (l.stillalive() == false) {
- break;
- }
- if (i < moves - 1) {
- l.nextmove(height, width);
- }
- }
- l.write();
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- if (tab[j][i] == 'a' - 1 || tab[j][i] == 'A' - 1) {
- tab[j][i] = '@';
- }
- cout << tab[j][i];
- }
- cout << endl;
- }
- /* for (int i=0; i <width; ++i) {
- delete[] tab[i];
- }
- delete[] tab;
- tab = NULL;*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement