Skip to content

Instantly share code, notes, and snippets.

@jwvg0425
Created November 4, 2020 01:29
Show Gist options
  • Save jwvg0425/ca34f3472475d0ec9b3ec20bddeb6794 to your computer and use it in GitHub Desktop.
Save jwvg0425/ca34f3472475d0ec9b3ec20bddeb6794 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
string str;
cin >> str;
int nowk = 0;
int count = 0;
int idx = 0;
while (idx < m)
{
if (nowk == 0)
{
if (str.substr(idx, 3) == "IOI")
{
nowk++;
idx += 2;
}
idx++;
continue;
}
if (str.substr(idx, 2) == "OI")
{
nowk++;
idx += 2;
continue;
}
count += max(0, nowk - n + 1);
nowk = 0;
}
count += max(0, nowk - n + 1);
cout << count << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment