#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 比较函数,用于 qsort 排序
int compare(const void *a, const void *b) {
char *str1 = *(char **)a;
char *str2 = *(char **)b;
return strcmp(str1, str2);
}
// 生成组合词的函数
void generateCombinations(char *words[], int count) {
// 生成所有可能的两个汉字组合
for (int i = 0; i < count; i++) {
for (int j = i + 1; j < count; j++) {
char combinedWord[50];
sprintf(combinedWord, “%s%s”, words[i], words[j]);
printf("%s “, combinedWord);
}
}
printf(”\n");
}
int main() {
// 假设的词库,实际应用中需要一个完整的词典
char* dictionary[] = {“州”, “汗”, “污”, “江”, “池”, “汤”, “忙”, “兴”, “宇”, “守”, “宅”, “字”, “安”, “讲”, “军”, “许”, “论”, “农”, “讽”, “设”, “访”, “寻”, “那”, “迅”, “尽”, “导”, “异”, “孙”, “阵”, “阳”, “利”};
int dictionarySize = sizeof(dictionary) / sizeof(dictionary[0]);
// 生成组合词
generateCombinations(dictionary, dictionarySize);
// 释放动态分配的内存
// 注意:这里没有实际分配内存,所以不需要释放
return 0;
}