/* cheat2.c by Shawn Nematbakhsh snematbakhsh@cs.ucr.edu * Takes a list of letter tiles and a number of wild tiles(0-9) as * args, and outputs a list of possible letters that can be played off * of to use all your tiles to make a valid word. So run cheat2 on your * tiles, and if the output matches one of the open tiles on the board * then run cheat.c to see what ultimate word you can make and then * play it. */ #include #include #include #define MAX_SIZE 100 int main(int argc, char **argv) { int c[26]; int cc[26]; int i; FILE *fp; char word[30]; char *p; int dif; int adds[26]; int l; for(i=0;i<26;++i) { c[i]=0; adds[i]=0; } if(argc != 3) { printf("Check usage\n"); return 0; } l=strlen(argv[1]); while(*argv[1] != '\0') c[*argv[1]++ - 'a']++; if((fp=fopen("dict.txt","r"))==NULL) { printf("Can't open file\n"); return 0; } while((fscanf(fp,"%s\n",word))!= EOF) { if(strlen(word) != l+argv[2][0]-'0'+1) continue; p=word; dif=0; for(i=0;i<26;++i) cc[i]=0; while(*p != '\0') cc[*p++ - 'a']++; for(i=0;i<26;++i) { if(cc[i]>c[i]) dif+=cc[i]-c[i]; if(dif>argv[2][0]-'0'+1) break; } if(dif==argv[2][0]-'0'+1) { for(i=0;i<26;++i) if(cc[i]>c[i]) adds[i]=1; } } printf("Adds:\n"); for(i=0;i<26;++i) if(adds[i]==1) printf("%c ",i+'a'); printf("\n"); return 0; fclose(fp); }