Language: C++



int main()
{
    int n = 1;
    while (1){
        int m = 0;
        int count = 0;
        std::string str;

        std::string check;

        std::cin >> n;

        if (n == 0) {
            break;
        }

        for (int i = 0; i < n; i++) {
            check += "I";
            check += "O";
            if (i == n - 1) {
                check += "I";
            }
        }

    //std::cout << check << std::endl;

        std::cin >> m;

        std::cin >> str;

        std::string current;
        for (int i = 0; i < m; i++) {
            if (i >= m - 2 * n) {
                break;
            }

            for (int j = i; j < i + 2 * n + 1; j++) {
                if (j >= m) {
                    continue;
                }
                current += str[j];
            }

            if (current == check) {
                count += 1;
            }

            current = "";



        }

        std::cout << count << std::endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:14: error: 'string' is not a member of 'std'
    9 |         std::string str;
      |              ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | 
a.cc:11:14: error: 'string' is not a member of 'std'
   11 |         std::string check;
      |              ^~~~~~
a.cc:11:14: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:13:14: error: 'cin' is not a member of 'std'
   13 |         std::cin >> n;
      |              ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:20:13: error: 'check' was not declared in this scope
   20 |             check += "I";
      |             ^~~~~
a.cc:29:14: error: 'cin' is not a member of 'std'
   29 |         std::cin >> m;
      |              ^~~
a.cc:29:14: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:31:14: error: 'cin' is not a member of 'std'
   31 |         std::cin >> str;
      |              ^~~
a.cc:31:14: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:31:21: error: 'str' was not declared in this scope; did you mean 'std'?
   31 |         std::cin >> str;
      |                     ^~~
      |                     std
a.cc:33:14: error: 'string' is not a member of 'std'
   33 |         std::string current;
      |              ^~~~~~
a.cc:33:14: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:43:17: error: 'current' was not declared in this scope
   43 |                 current += str[j];
      |                 ^~~~~~~
a.cc:46:17: error: 'current' was not declared in this scope
   46 |             if (current == check) {
      |                 ^~~~~~~
a.cc:46:28: error: 'check' was not declared in this scope
   46 |             if (current == check) {
      |                            ^~~~~
a.cc:50:13: error: 'current' was not declared in this scope
   50 |             current = "";
      |             ^~~~~~~
a.cc:56:14: error: 'cout' is not a member of 'std'
   56 |         std::cout << count << std::endl;
      |              ^~~~
a.cc:56:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:56:36: error: 'endl' is not a member of 'std'
   56 |         std::cout << count << std::endl;
      |                                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 |