fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int ishyphen(int ch) {
  5. return ch == '-';
  6. }
  7.  
  8. int isdate(const char *s) {
  9. unsigned q;
  10. int (*f[])(int)= {
  11. isdigit, isdigit, ishyphen,
  12. };
  13.  
  14. for (q=0; q < sizeof f / sizeof *f; ++q)
  15. if (!f[q](s[q]))
  16. return 0;
  17.  
  18. return !s[q];
  19. }
  20.  
  21. int main(void) {
  22. char s[256];
  23.  
  24. while(gets(s)) {
  25. printf("%s - %s\n", s, isdate(s) ? "yes" : "no");
  26. }
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 2116KB
stdin
2015-09-01
2015-08-aa
2012/08-26
2015-08-_26
2012/aa-26
2012--8-26
2012=08-26
2014-028-26
2011-(8-26
2011-(--26
2011----26
2311-(8-26
stdout
2015-09-01 - yes
2015-08-aa - no
2012/08-26 - no
2015-08-_26 - no
2012/aa-26 - no
2012--8-26 - no
2012=08-26 - no
2014-028-26 - no
2011-(8-26 - no
2011-(--26 - no
2011----26 - no
2311-(8-26 - no