fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdbool.h>
  5.  
  6. int main() {
  7. char input[99999];
  8. char output[99999];
  9. scanf(" %[^\n]", input);
  10.  
  11. int in_len = strlen(input);
  12. int out_len = 0;
  13. int start = 0;
  14.  
  15. while(input[start] == ' ') start++;
  16.  
  17. if(start >= in_len){
  18. printf("No words!");
  19. return 0;
  20. }
  21.  
  22. bool space = false;
  23. bool isWord = false;
  24.  
  25. for(int i = start; i < in_len; i++){
  26. if(input[i] == ' '){
  27. if(space){
  28. continue;
  29. }
  30. else{
  31. space = true;
  32. output[out_len++] = input[i];
  33. }
  34. }
  35. else {
  36. output[out_len++] = input[i];
  37. isWord = true;
  38. space = false;
  39. }
  40. }
  41.  
  42. while(out_len > 0 && output[out_len - 1] == ' '){
  43. out_len--;
  44. }
  45.  
  46. output[out_len] = '\0';
  47.  
  48. if(isWord){
  49. printf("%s", output);
  50. }
  51. else{
  52. printf("No words!");
  53. }
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 5320KB
stdin
          
stdout
No words!