Source code for submission s1211

Go to diff to previous submission

bugs.cpp

  1. //
  2. // File: mosquito.cc
  3. // Author: cteam035
  4. //
  5. // Created on October 27, 2012, 11:23 AM
  6. //
  7.  
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #include <cstring>
  11. #include <string>
  12. #include <string>
  13. #include <iostream>
  14.  
  15.  
  16.  
  17. using namespace std;
  18. //
  19. //
  20. //
  21.  
  22. #define MAXCHAR 2000002
  23. #define MAXSTR 1005
  24.  
  25. class Stack{
  26. public:
  27. Stack();
  28. ~Stack();
  29. void setRet(const string & str);
  30. // top -- jaky potrebuju
  31. bool top(char& c, int& i) const;
  32. char first(void) const;
  33. bool push(char c, int i);
  34. void check();
  35. void vysypej();
  36. bool isEmpty(void) const;
  37.  
  38. private:
  39. char poleC[MAXCHAR];
  40. int poleI[MAXCHAR];
  41. int vrchol;
  42. char retezec[MAXSTR];
  43. int delkaRet;
  44. };
  45.  
  46. Stack::Stack() {
  47. vrchol = 0;
  48. retezec[0]='\0';
  49. delkaRet=0;
  50. }
  51.  
  52. Stack::~Stack() {
  53.  
  54. }
  55.  
  56. bool Stack::isEmpty(void) const {
  57. return vrchol == 0;
  58. }
  59.  
  60. void Stack::setRet(const string & str){
  61. strncpy(retezec, str.c_str(), MAXSTR);
  62. delkaRet=str.length();
  63. }
  64.  
  65. char Stack::first() const {
  66. return retezec[0];
  67. }
  68.  
  69. bool Stack::top(char& c, int& i) const {
  70. if (isEmpty())
  71. i=0;
  72. else
  73. i = poleI[vrchol-1]+1;
  74. c = retezec[i];
  75. return true;
  76. }
  77.  
  78. bool Stack::push(char c, int i) {
  79. if ( vrchol >= MAXCHAR )
  80. return false;
  81. poleC[vrchol]=c;
  82. poleI[vrchol]=i;
  83. vrchol++;
  84. poleC[vrchol]='\0';
  85. return false;
  86. }
  87.  
  88. void Stack::check(){
  89. int i;
  90. for ( i=0; i<delkaRet; i++) {
  91. if ( poleC[vrchol-1-i] != retezec[delkaRet-1-i] )
  92. return;
  93. }
  94. vrchol-=delkaRet;
  95.  
  96. }
  97.  
  98. void Stack::vysypej(){
  99. printf("%s",poleC);
  100. // for ( int i=0; i<vrchol; i++ ){
  101. // fputc(poleC[i],stdout);
  102. // }
  103. poleC[0]='\0';
  104. vrchol=0;
  105. }
  106.  
  107. int main(int argc, char** argv) {
  108. Stack* stack = new Stack();
  109. int nlines, n, index;
  110. char c, expect, prvni;
  111. string bug;
  112.  
  113. while ( cin >> n >> bug ) {
  114. fgetc(stdin);
  115. stack->setRet(bug);
  116.  
  117. nlines=0;
  118. c='\0';
  119. while ( nlines < n ) {
  120. c = fgetc(stdin);
  121. if ( c == '\n' ) {
  122. nlines++;
  123. stack->push(c, -1);
  124. stack->vysypej();
  125. continue;
  126. }
  127.  
  128. prvni = stack->first();
  129. stack->top(expect, index);
  130. if ( expect == c ) {
  131. stack->push(c, index);
  132. stack->check();
  133. }
  134. else if ( prvni == c ){
  135. stack->push(c, 0);
  136. stack->check();
  137. }
  138. else {
  139. stack->push(c, -1);
  140. }
  141. }
  142. }
  143.  
  144. return (EXIT_SUCCESS);
  145. }
  146.  
  147.  

Diff to submission s1141

bugs.cpp

--- c4.s1141.cteam035.bugs.cpp.0.bugs.cpp
+++ c4.s1211.cteam035.bugs.cpp.0.bugs.cpp
@@ -121,6 +121,6 @@
             if ( c == '\n' ) {
                 nlines++;
+                stack->push(c, -1);
                 stack->vysypej();
-                fputc(c,stdout);
                 continue;
             }
@@ -137,6 +137,5 @@
             }
             else {
-                stack->vysypej();
-                fputc(c,stdout);
+                stack->push(c, -1);
             }
         }