Go to diff to previous submission
#include <iostream> #include <stdio.h> #include <string> #include <string.h> using namespace std; class node { public: node * prev; node * next; char val; node(char a) { prev = next = NULL; val = a; } }; class linkedlist { public: node * start; node * end; node * actual; void create(const char * arr) { start = end = actual = NULL; node * tmp = NULL; node * old = NULL; while(*arr) { tmp = new node(*arr); tmp->prev = old; if (old) old->next = tmp; else start = tmp; old = tmp; //printf("%s\n", megarr); arr++; } if (tmp) tmp->next = NULL; end = tmp; actual = start; } void goback(int steps) { if (start == NULL) return; while(steps--) { if (!actual->prev) return; actual = actual->prev; } } bool contain(const char * str, int stringlen) { if (start == NULL) return false; node * ptr = actual; while(stringlen--) { if (!ptr || ptr->val != *(str++)) return false; ptr = ptr->next; } return true; } void del(int size) { //print(); node * tosetprev = actual->prev; while(size--) { node * tmp = actual; actual = actual->next; delete tmp; } if (!actual) { actual=tosetprev; if (tosetprev) tosetprev->next = NULL; } else { actual->prev = tosetprev; if (tosetprev) tosetprev->next = actual; } if(!tosetprev) start = actual; //print(); } bool notEnd() { return actual; } void gonext() { actual = actual->next; } void print() { node * tmp = start; while(tmp) { printf("%c",tmp->val); tmp = tmp->next; } printf("\n"); } }; int main () { char * bug = new char[2000001]; int lines, buglen; char * megarr = new char[2000001]; while ( scanf("%d %s\n", &lines ,bug) == 2 ) { //cout << "line: " << lines << endl; buglen = strlen(bug); while (lines--) { cin.getline(megarr,2000000,'\n'); linkedlist ll; ll.create(megarr); while(ll.notEnd()) { if (ll.contain(bug,buglen)) { ll.del(buglen); ll.goback(buglen); } else { ll.gonext(); } } ll.print(); } } return 0; }
--- c4.s1331.cteam023.bugs.cpp.0.bugs.cpp +++ c4.s1399.cteam023.bugs.cpp.0.bugs.cpp @@ -51,4 +51,5 @@ void goback(int steps) { + if (start == NULL) return; while(steps--) { @@ -61,4 +62,5 @@ bool contain(const char * str, int stringlen) { + if (start == NULL) return false; node * ptr = actual; while(stringlen--) @@ -94,4 +96,6 @@ if(!tosetprev) start = actual; + + //print(); }