hyunjin

[코딩도장]45.8 특정 단어 개수 세기 본문

알고리즘 연습/코딩도장

[코딩도장]45.8 특정 단어 개수 세기

_h.j 2019. 7. 22. 14:05
728x90

-scanf로 공백 포함해서 입력 받기

-strtok로 문자를 제외한 나머지로 분리하고

-strcmp로 the와 비교해 맞으면  count

 

 

ptr = strtok(s, "[^abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUWVXYZ]");

이렇게 하려면 어떻게 해야할까

 

 

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include

int main() {
int count = 0;
char s[1000], * ptr = strtok(s, ",.- ");
scanf("%[^\n]s",s);

while (ptr != NULL) {
if (ptr != NULL && !strcmp(ptr, "the")) count++;
ptr = strtok(NULL, ",.- ");
}
printf("%d", count);
return 0;
}

 

 

 

728x90