Go to diff to previous submission
#include <string> #include <iostream> using namespace std; int T; string bugText; int lineEnds; bool bugComplete(string text) { if (text.size() != bugText.size()) return false; int i = text.size() -1; return text[i] == bugText[i]; //return text == bugText; } bool bugStart(char ch) { if (ch == bugText[0]) return true; return false; } bool bugFailed(string text) { if (text.size() > bugText.size()) return true; int i = text.size() -1; return text[i] != bugText[i]; /* for (int i = text.size() -1 ; i >= 0; --i) { if (text[i] != bugText[i]) return true; }*/ return false; } string readBug() { string text; while (lineEnds < T) { char ch; ch = cin.get(); if (ch == '\n') { //cout << "endl" << endl; lineEnds++; text += ch; continue; } if (bugStart(ch)) { //cout << "bugstart" << endl; if (text.empty()) text += ch; else { cin.unget(); text += readBug(); } } else { //cout << "check bug" << endl; text += ch; if (bugComplete(text)) { //cout << "bug complete!!" << endl; return ""; } if (bugFailed(text)) return text; } } return text; } string baseLoop() { string text; while (lineEnds < T) { char ch; ch = cin.get(); if (ch == '\n') { // cout << "endl" << endl; lineEnds++; text += ch; continue; } if (bugStart(ch)) { //cout << "bugstart" << endl; cin.unget(); text += readBug(); } else text += ch; } return text; } int main() { while (true) { cin >> T; cin >> bugText; if (!cin.good()) { break; } lineEnds = 0; char ch; ch = cin.get(); if (ch != '\n') cin.unget(); cout << baseLoop() << endl; } }
--- c4.s995.cteam054.bugs.cpp.0.bugs.cpp +++ c4.s1006.cteam054.bugs.cpp.0.bugs.cpp @@ -31,9 +31,12 @@ return true; - for (int i = text.size() -1 ; i >= 0; --i) + int i = text.size() -1; + return text[i] != bugText[i]; + + /* for (int i = text.size() -1 ; i >= 0; --i) { if (text[i] != bugText[i]) return true; - } + }*/ return false;