C/문법
[C] 백준 1152 - 공백 포함 scanf
Rix
2022. 4. 25. 01:26
#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로 했다.