Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 28, 2019 04:02
Show Gist options
  • Save surinoel/cbd36ba7bb6b58690bcb35bcd0caaac6 to your computer and use it in GitHub Desktop.
Save surinoel/cbd36ba7bb6b58690bcb35bcd0caaac6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
char buf[10001];
int main(void) {
scanf("%s", buf);
int cnt1 = 0;
char *ptr = strstr(buf, "JOI");
while (ptr != NULL) {
cnt1 += 1;
ptr = strstr(ptr + 2, "JOI");
}
printf("%d\n", cnt1);
int cnt2 = 0;
ptr = strstr(buf, "IOI");
while (ptr != NULL) {
cnt2 += 1;
ptr = strstr(ptr + 1, "IOI");
}
printf("%d\n", cnt2);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
string str;
int joi, ioi;
int main(){
cin >> str;
size_t pos = 0;
while((pos = str.find("JOI", pos)) != string::npos) joi++, pos++;
pos = 0;
while((pos = str.find("IOI", pos)) != string::npos) ioi++, pos++;
cout << joi << '\n' << ioi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment