1152번 - 단어의 개수
아래가 코드구요. 어디가 이상있는지 못찾겠습니다 ㅠㅠ 도와주세요!!
#include <stdio.h>#include <string.h>#include <stdlib.h>int main(void){ int i=0,N=0,j=0; char ch[1000001]={0}; int cnt=1; int space=0; scanf("%[^\n]",&ch);
while(1) { if(ch[i]==' ') { if(space==0) { cnt++; } space=1; } else if(ch[i]==0) { if(ch[i-1]==' ') { cnt--; } break; } else { space=0; } i++; } printf("%d\n",cnt);
return 0;}
댓글을 작성하려면 로그인해야 합니다.
junsung91 6년 전
아래가 코드구요. 어디가 이상있는지 못찾겠습니다 ㅠㅠ 도와주세요!!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int i=0,N=0,j=0;
char ch[1000001]={0};
int cnt=1;
int space=0;
scanf("%[^\n]",&ch);
while(1)
{
if(ch[i]==' ')
{
if(space==0)
{
cnt++;
}
space=1;
}
else if(ch[i]==0)
{
if(ch[i-1]==' ')
{
cnt--;
}
break;
}
else
{
space=0;
}
i++;
}
printf("%d\n",cnt);
return 0;
}