#include #include #include #include #define MAXLEN 25 #define MAXLINE 100 #define MAXWORDS 500 #define DELIM "BULLSHIT" #define INFILE "bingo.in" struct sWord { char word[30]; int index; }; int gcd(int a, int b) { int i, max, maxdiv = -1; max = (a > b) ? a : b; for (i = 1; i <= a; ++i) { if ( (a % i == 0) && (b % i == 0) ) { maxdiv = i; } } return maxdiv; } int countWords(struct sWord *words, int n) { int i, unique, j; int min, max; int count = 0; for (i = 0; i < 510; ++i) { if (words[i].index == n) { min = i; break; } } for (i = 0; i < 510; ++i) { if (words[i].index == n) { max = i; } } for (i = min; i <= max; ++i) { unique = 1; for (j = i - 1; j >= min; --j) { if (!strcmp(words[j].word, words[i].word)) { unique = 0; break; } } if (unique) count++; } return count; } void cleanse(char *str) { int i; char c; for (i = 0; i < strlen(str); ++i) { c = str[i]; /* if ( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ) */ if (islower(c) || isupper(c)) continue; else str[i] = ' '; } } int main(void) { char line[MAXLINE + 2]; struct sWord words[510000]; int i, k, j; int curindex, totalCount = 0; int bullshits = 0; char *s = "%"; char *curword; char t[30]; FILE *fp; fp = fopen(INFILE, "r"); if (fp == NULL) { puts("moo"); return 1; } curindex = 0; bullshits = 0; for (i = 0; i < 510; ++i) { words[i].index = -1; strcpy(words[i].word, "GAAARnix"); } while (s != NULL) { /* ZEILEN */ s = fgets(line, MAXLINE + 1, fp); if (s == NULL) break; cleanse(line); curword = strtok(line, " "); if (curword == NULL) continue; if (!strcmp(curword, DELIM)) { bullshits++; } else { strncpy(words[curindex].word, curword, 29); words[curindex++].index = bullshits; } while (curword != NULL) { curword = strtok(NULL, " "); if (curword == NULL) break; if (!strcmp(curword, DELIM)) { bullshits++; continue; } else { strncpy(words[curindex].word, curword, 29); words[curindex++].index = bullshits; } } /* WORDS */ } i = 0; while (words[i].index != -1) { ++i; } for (i = 0; i < 4; ++i) { } for (i = 0; i < bullshits; ++i) { totalCount += countWords(words, i); } if ((totalCount == 0) || (bullshits == 0)) { printf("0 / 1\n"); return 0; } printf ("%d / %d\n", totalCount / gcd(totalCount, bullshits), bullshits / gcd(totalCount, bullshits)); fclose(fp); return 0; }