字符全排列
来源:互联网 发布:孔玮怎么样知乎 编辑:程序博客网 时间:2024/05/17 04:37
Description
You are to write a program that has to generate all possible words from a given set of letters.
Example: Given the word "abc", your program should - by exploring all different combination of the three letters - output the words "abc", "acb", "bac", "bca", "cab" and "cba".
In the word taken from the input file, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order.
Example: Given the word "abc", your program should - by exploring all different combination of the three letters - output the words "abc", "acb", "bac", "bca", "cab" and "cba".
In the word taken from the input file, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order.
Input
The input consists of several words. The first line contains a number giving the number of words to follow. Each following line contains one word. A word consists of uppercase or lowercase letters from A to Z. Uppercase and lowercase letters are to be considered different. The length of each word is less than 13.
Output
For each word in the input, the output should contain all different words that can be generated with the letters of the given word. The words generated from the same input word should be output in alphabetically ascending order. An upper case letter goes before the corresponding lower case letter.
Sample Input
3aAbabcacba
Sample Output
AabAbaaAbabAbAabaAabcacbbacbcacabcbaaabcaacbabacabcaacabacbabaacbacabcaacaabcabacbaa
/**这个题由于一个小错误被我提交了n次,终于被我改对了,可是感觉心好累啊!!一开始问学长,学长说我思路有问题,其实就是在next_permutation()里面少了一个cmp而已,结果害的我。。。。。不说了*/#include<cstring>#include<string>#include<cstdio>#include<algorithm>using namespace std;bool cmp(char x, char y){ double aa = (double)x; double bb = (double)y; if(aa > 90) aa = aa - 31.5; if(bb > 90) bb = bb - 31.5; return aa < bb;}int main(){ int N; scanf("%d",&N); while(N--) { char a[20]; scanf("%s",a); sort(a,a+strlen(a),cmp); do { printf("%s\n",a); } while(next_permutation(a,a+strlen(a),cmp)); } return 0;}
0 0
- 字符的全排列
- 字符全排列
- 字符全排列Permutation
- 字符全排列
- 字符全排列算法
- 字符全排列产生器
- 字符的全排列
- 字符全排列
- 字符全排列
- 字符的全排列
- 字符全排列
- 四个字符全排列
- 字符的全排列
- 字符全排列
- 字母字符全排列
- 计蒜客-字符全排列
- dfs-字符全排列
- 算法题--字符排列(全排列)
- 树形结构 数据组织方式
- 素材库亮相CityMaker7.0,轻松解决“烦人”的模型管理问题
- java的循环引用
- SET FOREIGN_KEY_CHECKS=0;在Mysql中取消外键约束。
- oracle PL/SQL
- 字符全排列
- phonegap ios7 启动页缩小,有白色底边
- 欢迎使用CSDN-markdown编辑器01
- 横向划屏
- c#反射重载方法(发现不明确的匹配)
- java基本类型的内存中占用字节数
- 基于docker搭建hadoop分布式集群(一)
- 01背包问题
- 使用apache mina实现简单心跳服务