20250804 baekjoon
This commit is contained in:
parent
3ff16c6bff
commit
af7c3c145f
40
code_study/Baekjoon/c/5525.c
Normal file
40
code_study/Baekjoon/c/5525.c
Normal 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;
|
||||||
|
}
|
||||||
19
code_study/Baekjoon/python/5525.py
Normal file
19
code_study/Baekjoon/python/5525.py
Normal 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)
|
||||||
Loading…
x
Reference in New Issue
Block a user