fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #define is_delim(c) (isspace((c)) || ispunct((c)))
  4. #define N_EVEN 1
  5. #define N_ODD 2
  6.  
  7.  
  8. int is_altern(const char* s){
  9. const char* p;
  10. int j, n = 0, i = 0, r = (*s != '\0');
  11.  
  12. for(; *s; s = p){
  13. while(is_delim(*s))
  14. ++s;
  15.  
  16. for(p = s; *p && !is_delim(*p); ++p)
  17. ;
  18.  
  19. if((j = (int)(p - s)) > 0){
  20. if(j & 1)
  21. i = N_ODD;
  22. else
  23. i = N_EVEN;
  24.  
  25. if(i != n)
  26. n = i;
  27. else {
  28. r = 0;
  29. break;
  30. }
  31. }
  32. }
  33. return r;
  34. }
  35.  
  36.  
  37. int main(void){
  38. puts( is_altern("lisp, apl, pascal.") ? "yes" : "no");
  39. puts( is_altern("titan moon (venus)") ? "yes" : "no");
  40. puts( is_altern("Forth Java Prolog") ? "yes" : "no");
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
yes
yes
no