fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6. char word[1000001] = { 0, };
  7. int count = 1;
  8. gets(word); //scanf는 공백을 못받음
  9. if (word[0] == '\0') { //\n만 입력되는 경우(그냥 엔터키)
  10. printf("%d",count-1);
  11. return 0;
  12. }
  13. int w = strlen(word);
  14. for (int i = 1; i < w; i++) {
  15. if (word[i - 1] != ' ') {
  16. if (word[i] == ' ' && word[i + 1] != '\0' ) {
  17. count++;
  18. }
  19. }
  20. }
  21. if ((w == 1) && (word[0] = ' ')) //공백이 입력되는 경우
  22. printf("%d", count - 1);
  23.  
  24. else
  25. printf("%d", count);
  26.  
  27.  
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 4900KB
stdin
a
stdout
Standard output is empty