fork download
  1. #include <iostream>
  2.  
  3.  
  4. struct AbstractFile
  5. {
  6. char read_at_offset(int _n) = 0;
  7. };
  8.  
  9. void assess(char _s, int& _opened)
  10. {
  11. if (_s == '(')
  12. ++_opened;
  13. else
  14. --_opened;
  15. }
  16.  
  17. int main()
  18. {
  19. int n = 100;
  20. k = 4;
  21. if (k%2) return;
  22. AbstractFile* file = nullptr;
  23.  
  24. int opened = 0;
  25. int correct_sequencies_n = 0;
  26.  
  27. {
  28. char s = 0;
  29. for (int i = 0; i < k; ++i)
  30. {
  31. s = file->read_at_offset(i);
  32. assess(s, _opened);
  33. }
  34. }
  35.  
  36. if (opened == 0)
  37. ++correct_sequencies_n;
  38. int first = 0;
  39. for (int i = k; i < n; ++i)
  40. {
  41. // shift right by one element
  42.  
  43. // throw away first element
  44. if (file->read_at_offset(first) == '(')
  45. --_opened;
  46. else
  47. ++_opened;
  48.  
  49. // consider new last element
  50. assess(file->read_at_offset(first+k), _opened);
  51. ++first;
  52. if (opened == 0)
  53. ++correct_sequencies_n;
  54. }
  55. }
  56.  
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:10: error: initializer specified for non-virtual method 'char AbstractFile::read_at_offset(int)'
     char read_at_offset(int _n) = 0;
          ^
prog.cpp: In function 'int main()':
prog.cpp:20:5: error: 'k' was not declared in this scope
     k = 4;
     ^
prog.cpp:21:14: error: return-statement with no value, in function returning 'int' [-fpermissive]
     if (k%2) return;
              ^
prog.cpp:32:23: error: '_opened' was not declared in this scope
             assess(s, _opened);
                       ^
prog.cpp:45:15: error: '_opened' was not declared in this scope
             --_opened;
               ^
prog.cpp:47:15: error: '_opened' was not declared in this scope
             ++_opened;
               ^
prog.cpp:50:47: error: '_opened' was not declared in this scope
         assess(file->read_at_offset(first+k), _opened);
                                               ^
stdout
Standard output is empty