20250804 baekjoon

This commit is contained in:
songyc macbook 2025-08-04 23:07:18 +09:00
parent 3ff16c6bff
commit af7c3c145f
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool isIOI(char* str, int index);
int main(){
int N, M;
scanf("%d %d\n",&N,&M);
char* S = (char*)malloc(M+1);
fgets(S, M+1, stdin);
int oiCount = 0, result = 0, i = 0;
while(i<M-1){
if(isIOI(S,i)){
oiCount++;
i += 2;
if(oiCount==N){
result++;
oiCount--;
}
}
else{
oiCount = 0;
i++;
}
}
printf("%d\n",result);
free(S);
return 0;
}
bool isIOI(char* str, int index){
return (str[index] == 'I' && str[index+1] == 'O' && str[index+2] == 'I') ? true : false;
}

View File

@ -0,0 +1,19 @@
import sys
input = sys.stdin.readline
N, M, S = int(input()), int(input()), input().rstrip()
result = OIcount = i = 0
while i < M-1:
if S[i:i+3] == "IOI":
OIcount += 1
i += 2
if OIcount == N:
result += 1
OIcount -= 1
else:
OIcount = 0
i += 1
print(result)