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. 基于pymysql模块的增删改查

    上课笔记 重点:(熟练)多表查询创建存储过程原生sql索引原理 pymysql 封装好的客户端cursor 底层就是一个send操作commit 告诉mysql真的要完成修改操作(不然修改不会生效)e ...

  2. Java&Xml教程(十一)JAXB实现XML与Java对象转换

    JAXB是Java Architecture for XML Binding的缩写,用于在Java类与XML之间建立映射,能够帮助开发者很方便的將XML和Java对象进行相互转换. 本文以一个简单的例 ...

  3. 为Qt添加SSL支持

    目标:为Qt添加SSL支持,使得应用可以发送HTTPS请求 环境:win7,Qt4.8.6 步骤: 1.到http://slproweb.com/products/Win32OpenSSL.html下 ...

  4. word打印小册子

    使用联想m7250f打印册子,打印时设置该打印机属性为双面打印(手动),打印第一面后,将所有打印出的纸拿出并翻转使对应word中的第2页的打印纸朝外,之后将所有纸放入纸盒,再点击打印第二面即可.

  5. Monkeyrunner介绍

    Monkeyrunner概述 Monkeyrunner是由Google开发.用于android系统的自动化测试工具,由android系统自带,存在于android sdk中(sdk:software ...

  6. Animate.css_css3动画库介绍

    插件描述:Animate.css内置了很多典型的css3动画,兼容性好使用方便. Animate.css是一个有趣的,跨浏览器的css3动画库.很值得我们在项目中引用. 用法 1.首先引入animat ...

  7. Hadoop伪集群部署

    环境准备 [root@jiagoushi ~]# yum -y install lrzsz 已加载插件:fastestmirror Repository 'saltstack-repo': Error ...

  8. Unity整合Asp.Net MVC

    先来看一下我们的解决方案 我们建立Yubay.Models项目, using System; using System.Collections.Generic; using System.Data.E ...

  9. mkdir与makedirs

    mkdir创建的是一级目录 makedirs可以创建多级目录 mkdir -p可以递归创建目录

  10. Crashlytics Android 异常报告统计管理

    http://www.infoq.com/cn/articles/crashlytics-crash-statistics-tools 简介 Crashlytic 成立于2011年,是专门为移动应用开 ...