Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %lld & %llu

Submit Status

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'.

Source

先将每个字符按从小到大排序,然后搜一个全排列出来就行。

然而也有更流氓(误)的方法——next_permutation

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int cmp(char a,char b){
if(tolower(a)==tolower(b))
return a<b;
else return tolower(a)<tolower(b);
}
int n;
string s;
int main(){
scanf("%d",&n);
while(n--){
cin>>s;
sort(s.begin(),s.end(),cmp);
do{
cout<<s<<endl;
}while(next_permutation(s.begin(),s.end(),cmp));
}
return ;
}

POJ1256 Anagram的更多相关文章

  1. Anagram

    Anagram poj-1256 题目大意:给你n个字符串,求每一个字符串所有字符的全排列,按照顺序输出所有全排列. 注释:每一个字符长度小于13,且字符排序的顺序是:A<a<B<b ...

  2. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  3. Leetcode Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  4. LeetCode 242 Valid Anagram

    Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...

  5. 【09_242】Valid Anagram

    Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...

  6. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  7. 242. Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  8. (easy)LeetCode 242.Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  9. 【LeetCode】242 - Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

随机推荐

  1. AndroidStudio中使用SVN

    AndroidStudio中使用SVN提交项目 1.安装SVN,我选择使用TortoiseSVN-1.8.7.25475-x64-svn-1.8.9.msi(安装文件地址如下:http://downl ...

  2. SQL数据库学习,常用语句查询大全

    数据库学习 sql server数据库基本概念 使用文件保存数据存在几个缺点: 1.文件的安全性问题: 2.文件不利于查询和对数据的管理: 3.文件不利于存放海量数据 4.文件在程序中控制不方便. 数 ...

  3. Eigen3的安装

  4. 应用开始界面简单倒计时的dialog

    activity_main.xml 下面图片显示的还要在activity_main.xml里面加个TextView <?xml version="1.0" encoding= ...

  5. Git使用简析

    推送本地操作 初始化一个本地Git仓库,在需要添加版本控制的文件夹根目录中使用git init命令. 添加文件到本地Git仓库: git add 文件名 # 添加文件到暂存区 git add . # ...

  6. vue2.0组件生命周期探讨

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. caffe proto

    所在目录为: /src/caffe/proto 在caffe.proto中定义了很多结构化数据,比如LayerParameter.Datum.NetParameter.SolverParameter. ...

  8. git 添加外部项目地址

    github 提交第三方模块流程   // git config --global user.name 'your name' 可以设置全局用户名,在commit记录里显示的是这个配置设置的名称. / ...

  9. js实现返回上一页功能

    大家在做 "返回上一页" 这个功能的时候 都是用history.go(-1);来实现的 但这段代码只是简单的使用浏览器的后退功能 从浏览器缓存中取出页面来显示 但我们绝大部分情况都 ...

  10. mysql时间的处理

    mysql中格式化时间为: 1,DATE_FORMAT(APPLYDATE,'%Y-%m-%d %H:%i:%S') AS APPLYDATE 2,DATE_FORMAT(CHKSIGNDATE, ' ...