1 条题解
-
0
问题分析:
- 需要生成输入单词的所有排列组合
- 处理重复字母,避免输出重复结果
- 结果需按特定字母顺序排列
关键点:
- 排列生成算法
- 去重处理
- 自定义排序规则
解题步骤:
- 统计每个字母的出现频率
- 使用回溯法生成所有排列
- 使用集合去重
- 按自定义顺序排序结果
#include <algorithm> #include <cstring> #define AUTHOR "HEX9CF" using namespace std; //'A'<'a'<'B'<'b'<…<'Z'<'z' bool cmp(char x, char y) { if (tolower(x) == tolower(y)) { return x < y; } else { return tolower(x) < tolower(y); } } int main() { int n; cin >> n; while (n--) { char s[15]; int len = 0; cin >> s; len = strlen(s); sort(s, s + len, cmp); do { cout << s << endl; } while (next_permutation(s, s + len, cmp)); } return 0; }
- 1
信息
- ID
- 257
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者