int main(void) { #define anagram(a,b) do { \ printf(a " %s anagram of " b "\n", is_anagram((a),(b)) ? "is" : "is not"); \ } while(0) anagram("mary","army"); anagram("mary","ary"); anagram("hello","world"); anagram("anagram","anagram"); #undef anagram }
/** * Tries to generate a blank challenge. * @param word_length The total length of the word. * @param max_sol The number of maximum solutions allowed. * @param num_blanks Number of blanks. * @return 1 if success, 0 if failure */ int try_generate_blank_challenge(int word_length, int max_sol, int num_blanks, NODE* node, FILE* fp) { char str[16]; int success, i; gen_random_rack(str, word_length - num_blanks, num_blanks); success = anagram(node, str, "anagram", &answers, 0, max_sol); if (success) { for (i = 0; i < answers.num_answers; i++) { if (g_hash_table_contains(all_answers_hash, answers.answers[i])) { // This answer is already in the all_answers_hash; don't // allow. printf("Generated duplicate, ignoring, %s, %s\n", str, answers.answers[i]); cleanup_answers(&answers); return 0; } } fprintf(fp, "%s ", str); for (i = 0; i < answers.num_answers; i++) { add_to_hash(answers.answers[i]); fprintf(fp, "%s ", answers.answers[i]); } fprintf(fp, "\n"); cleanup_answers(&answers); } return success; }
int main() { printf("%d\n", (int) strlen(ascii_str)); printf("reverse: %s\n", reverse(ascii_str)); char frank[50] = "frankandbeans"; char beans[50] = "beansandfrank"; if (anagram(frank, beans)) { printf("Anagram true!\n"); } int testMatrix[3][3]; int testNum = 1; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { testMatrix[x][y] = testNum++; } } for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { printf("%d ", testMatrix[x][y]); } printf("\n"); } int** tempArray = (int)(malloc(sizeof(array))); memcpy(array, tempArray, sizeof(tempArray)); tempArray = rotate(testMatrix); for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { printf("%d ", testMatrix[x][y]); } printf("\n"); } }
int main(int argc, char **argv) { char input[10]; scanf("%s", input); int len = strlen(input); anagram(len, len, input); return 0; }
void anagram(int orgSize, int newSize, char *word) { if (newSize == 1) return; int j; for (j = 0; j < newSize; j++) { anagram(orgSize, newSize - 1, word); if (newSize == 2) displayWord(word); rotate(orgSize, newSize, word); } }
vector<vector<string>> groupAnagrams(vector<string>& strs) { unordered_map<string, multiset<string>> mp; for (string s : strs) { string t = s; sort(t.begin(), t.end()); mp[t].insert(s); } vector<vector<string>> anagrams; for (auto m : mp) { vector<string> anagram(m.second.begin(), m.second.end()); anagrams.push_back(anagram); } return anagrams; }
int main(int argc,char *argv[]) { int flag=0; char c[1000],a[1000]; gets(c); printf("\n"); gets(a); flag=anagram(a,c); if(flag) { printf("The two strings are anagrams\n"); } else { printf("The two strings are not anagrams\n"); } return 0; }
static int single(const struct wordlist * const wl, int argc, char * argv[]) { if (argc == 3) return anagram(wl, argv[2], strlen(argv[2]), prn, stdout); return usage(argv[0]); }