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.

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

3
aAb
abc
acba

Sample Output

Aab
Aba
aAb
abA
bAa
baA
abc
acb
bac
bca
cab
cba
aabc
aacb
abac
abca
acab
acba
baac
baca
bcaa
caab
caba
cbaa

Hint

An upper case letter goes before the corresponding lower case letter.
So the right order of letters is 'A'<'a'<'B'<'b'<...<'Z'<'z'.
 
STL的全排列问题,写好排序方案,直接调用 next_permutation()函数便可!
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm> using namespace std; int n;
char str[15]; bool cmp(char a,char b)
{
if(tolower(a)==tolower(b))
return a<b;
else
return tolower(a)<tolower(b);
} int main()
{
scanf("%d",&T);
while( T-- )
{
scanf("%s",str);
sort(str,str+strlen(str),cmp);//自定义排序
do
{
cout << str << endl ;
}while(next_permutation(str,str+strlen(str),cmp));
} return 0;
}
 

ACM题目————Anagram的更多相关文章

  1. ACM题目————中缀表达式转后缀

    题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...

  2. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  3. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  4. 有一种acm题目叫做,奇葩!

    本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...

  5. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  6. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  7. ACM题目————又见拦截导弹

    描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...

  8. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  9. ACM题目————小A的计算器

    Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示.  现在小A要在这个操作系统上实现一个计算器,这 ...

随机推荐

  1. FTP规范

    FTP协议命令+返回值+返回值解析 FTP message format:FTP commands are Telnet strings terminated by the Telnet end of ...

  2. 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部

    1.监听按钮点击   2.判断是否是点击的同一个按钮(记录上次点击的按钮)   3.当重复点击相同按钮时,需要获取当前按钮对应控制器刷新界面      3.1 判断是否重复点击按钮,代码写在哪里?   ...

  3. 1029-对c语言文法的理解

    <程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...

  4. CentOS 7 下引导 Windows7 启动

    Win7/CentOS7 u盘安装后会覆盖硬盘上已有系统的’引导‘ CentOS7下恢复Win7引导 编辑 # vim /etc/grub.d/40_custom 添加 menuentry 'Wind ...

  5. csuoj 1111: 三家人

    acm.csu.edu.cn/OnlineJudge/problem.php?id=1111 1111: 三家人 Time Limit: 1 Sec  Memory Limit: 128 MBSubm ...

  6. 1.表单中 get与post提交方法的区别?

    get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. get是从服务器上获取数据,post是向服务器传送数据. GET方式提交的数据最多只能有102 ...

  7. Java参数按值传递?按引用传递

    有时候在想,java在调用方法时候究竟是按值传递还是按引用传递,之前有人说是基本数据类型按值传递,引用类型按引用传递.一时间,似乎都有道理. 笔者在此不追究字眼上的辨别识字能力,把自己对这个问题的理解 ...

  8. JSTL标签,EL表达式,OGNL表达式,struts2标签 汇总

    一下纯属个人总结摘抄,总结一起方便查看,解决疑问,有遗漏或错误,还请指出.       1,JSTL标签总结: a).JSTL标签有什么用?          JSTL是由JCP(Java Commu ...

  9. beta-1阶段各组员的贡献分分配

    小组名称:nice! 小组成员:李权 于淼 刘芳芳 韩媛媛 宫丽君 项目内容:约跑app 分数分配规则 个人贡献分=基本贡献分*0.2+特殊贡献分*0.3+个人代码贡献量*0.5 其中 基本贡献分,特 ...

  10. 3. 星际争霸之php设计模式--简单工厂模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...