#include <stdio.h>
#include <string.h>
int main(void)
{
char sent[1000000];
int count=0;
scanf("%[^\n]s", sent);
int len = strlen(sent);
for (int i = 0; i < len; i++)
{
if (sent[i] == ' ') count++;
}
if (sent[0] == ' ') count -= 1;
if (sent[len - 1] == ' ') count -= 1;
printf("%d", count+1);
return 0;
}
scanf("%[^\n]s", sent); // 엔터 전까지 입력받기 위해
원래 gets(sent);로 했는데 백준에서 컴파일 에러나서... scanf로 했다.
'C > 문법' 카테고리의 다른 글
[C] 백준 4673 - 재귀 함수 (0) | 2022.04.25 |
---|---|
[C] 백준 4344 - 형변환 (0) | 2022.04.25 |
[C] 백준 1546 - 배열 동적 할당 (0) | 2022.04.25 |
[C] 콘솔화면 초기화 방법 (0) | 2021.09.30 |
[C] 포인터 (0) | 2021.09.30 |