/* is_steal.c - determine if one word is a GrabScrab steal for another * Andrew Ho (andrew@zeuscat.com) * * GrabScrab rules can be found at http://www.grabscrab.com/. * * Build: gcc -Wall -o is_steal is_steal.c * Usage: is_steal bigword littleword */ #include #include #include int is_steal(char *big, char *little) { char used[26]; char *p; int i; for(i = 0; i < 26; i++) used[i] = 0; for(p = big; *p; p++) { if(isalpha((int)*p)) used[tolower((int)*p) - 'a']++; } for(p = little; *p; p++) { if(isalpha((int)*p)) { if(used[tolower((int)*p) - 'a'] == 0) return 0; else used[tolower((int)*p) - 'a']--; } } return 1; } int main (int argc, char **argv) { if(argc != 3) { fprintf(stderr, "usage: is_steal bigword littleword\n"); return 1; } else { printf( "%s %s a steal for %s\n", argv[1], is_steal(argv[1], argv[2]) ? "is" : "is not", argv[2] ); } return 0; }