Go to diff to previous submission
// // File: mosquito.cc // Author: cteam035 // // Created on October 27, 2012, 11:23 AM // #include <cstdlib> #include <cstdio> #include <cstring> #include <string> #include <string> #include <iostream> using namespace std; // // // #define MAXCHAR 2000002 #define MAXSTR 1005 class Stack{ public: Stack(); ~Stack(); void setRet(const string & str); // top -- jaky potrebuju bool top(char& c, int& i) const; char first(void) const; bool push(char c, int i); void check(); void vysypej(); bool isEmpty(void) const; private: char poleC[MAXCHAR]; int poleI[MAXCHAR]; int vrchol; char retezec[MAXSTR]; int delkaRet; }; Stack::Stack() { vrchol = 0; retezec[0]='\0'; delkaRet=0; } Stack::~Stack() { } bool Stack::isEmpty(void) const { return vrchol == 0; } void Stack::setRet(const string & str){ strncpy(retezec, str.c_str(), MAXSTR); delkaRet=str.length(); } char Stack::first() const { return retezec[0]; } bool Stack::top(char& c, int& i) const { if (isEmpty()) i=0; else i = poleI[vrchol-1]+1; c = retezec[i]; return true; } bool Stack::push(char c, int i) { if ( vrchol >= MAXCHAR ) return false; poleC[vrchol]=c; poleI[vrchol]=i; vrchol++; return false; } void Stack::check(){ int i; for ( i=0; i<delkaRet; i++) { if ( poleC[vrchol-1-i] != retezec[delkaRet-1-i] ) return; } vrchol-=delkaRet; } void Stack::vysypej(){ for ( int i=0; i<vrchol; i++ ){ fputc(poleC[i],stdout); } vrchol=0; } int main(int argc, char** argv) { Stack* stack = new Stack(); int nlines, n, index; char c, expect, prvni; string bug; while ( cin >> n >> bug ) { fgetc(stdin); stack->setRet(bug); nlines=0; c='\0'; while ( nlines < n ) { c = fgetc(stdin); if ( c == '\n' ) { nlines++; stack->vysypej(); fputc(c,stdout); continue; } prvni = stack->first(); stack->top(expect, index); if ( expect == c ) { stack->push(c, index); stack->check(); } else if ( prvni == c ){ stack->push(c, 0); stack->check(); } else { stack->vysypej(); fputc(c,stdout); } } } return (EXIT_SUCCESS); }
--- c4.s1114.cteam035.bugs.cpp.0.bugs.cpp +++ c4.s1124.cteam035.bugs.cpp.0.bugs.cpp @@ -97,6 +97,5 @@ void Stack::vysypej(){ for ( int i=0; i<vrchol; i++ ){ - cout << poleC[i]; - cout.flush(); + fputc(poleC[i],stdout); } vrchol=0; @@ -110,5 +109,5 @@ while ( cin >> n >> bug ) { - cin.get(); + fgetc(stdin); stack->setRet(bug); @@ -116,10 +115,9 @@ c='\0'; while ( nlines < n ) { - c = cin.get(); + c = fgetc(stdin); if ( c == '\n' ) { nlines++; stack->vysypej(); - cout << c; - cout.flush(); + fputc(c,stdout); continue; } @@ -137,6 +135,5 @@ else { stack->vysypej(); - cout << c; - cout.flush(); + fputc(c,stdout); } }