#include #include #include #include #include #define YL "kino" #define IN (argc > 1 ? argv[1] : YL ".sis") #define OUT (argc > 2 ? argv[2] : YL ".val") #define HINT (argc > 3 ? argv[3] : YL ".xxx") #define MAXLINE 100 void ERR(const char *s, ...) { printf("400\nError: "); va_list ap; va_start(ap, s); vprintf(s, ap); va_end(ap); printf("\n"); exit(0); } void OK(int n, const char *s, ...) { printf("200\nScore: %d\nError: ", n); va_list ap; va_start(ap, s); vprintf(s, ap); va_end(ap); printf("\n"); exit(0); } int isvoid(char c) { return c == 0 || isspace(c); } int cmp(const char *s1, const char *s2) { while (1) { while (isspace(*s1)) ++s1; while (isspace(*s2)) ++s2; while (1) { if (*s1 == 0 && *s2 == 0) return 0; if (isvoid(*s1) && isvoid(*s2)) break; if (*s1 < *s2) return -1; if (*s1 > *s2) return +1; ++s1; ++s2; } } } char s1[MAXLINE]; char s2[MAXLINE]; int n = 0; int main(int argc, const char *argv[]) { FILE *hint = fopen(HINT, "rt"); if (!hint) ERR("Viga vihjefaili avamisel"); FILE *out = fopen(OUT, "rt"); if (!out) OK(0, "Viga väljundfaili %s avamisel", OUT); while (fgets(s1, sizeof(s1), hint) != NULL) { ++n; if (fgets(s2, sizeof(s2), out) == NULL) OK(0, "Enneaegne väljundfaili lõpp"); if (cmp(s1, s2) != 0) OK(0, "Vale vastus real %d", n); } if (fscanf(out, "%10s", s2) > 0) OK(0, "Liigsed andmed väljundfaili lõpus"); OK(100, "OK"); }