Problem C
Generating Fast, Sorted Permutation
Input:Standard Input
Output:Standard Output
Generating permutation has always been an important problem in computer science. In this problem you will have to generate the permutation of a given string in ascending order.Remember that your algorithm must be efficient.
Input
The first line of the input contains an integer n, which indicates how many strings to follow. The next n lines contain n strings. Strings will only contain alpha numerals and never contain any space. The maximum length of
the string is 10.
Output
For each input string print all the permutations possible in ascending order. Not that the strings should be treated, as case sensitive strings and no permutation should be repeated. A blank line should follow each output set.
Sample Input
3
ab
abc
bca
Sample Output
ab
ba
abc
acb
bac
bca
cab
cba
abc
acb
bac
bca
cab
cba
和上一道题差不多,调用STL
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(char ch1,char ch2)
{
return ch1<ch2;
}
int main()
{
int n;
cin>>n;
while(n--)
{
string str;
cin>>str;
sort(str.begin(),str.end(),cmp);
int i,j;
cout<<str<<endl;
while(next_permutation(str.begin(), str.end()))
{
cout<<str<<endl;
}
cout<<endl;
}
return 0;
}
分享到:
相关推荐
Generating Functionology
Generating Artifacts问题三种解决办法
Generating Searchable Public-Key Ciphertexts With Hidden Structures for Fast Keyword Search
adv Generating a Map Application源码
adv Generating a Map Application 题目
Tom Copeland - Generating Parsers with JavaCC-Centennial Books (2009)
Episode-Based Prototype Generating Network for Zero-Shot Learning.pdf
Generating Random Networks and Graphs By 作者: Ton Coolen – Alessia Annibale – Ekaterina Roberts ISBN-10 书号: 0198709897 ISBN-13 书号: 9780198709893 Edition 版本: 1 出版日期: 2017-05-23 pages 页数...
此文档不完整,请下载另外一份。 谢谢大家支持我。
In this paper, we analyze the disadvantage of common generating test paper algorithms, an improved Particle Swarm Optimization is proposed and used in Auto-generating Test Paper Algorithm. We design ...
WC Yeh-universal generating MPs
Generating Word Reports _ Documentssrc1
关于泊松点过程的生成方法-Generating Homogeneous Poisson Processes - PDF.pdf 在百度上看很多人问平面内泊松点怎么生成,以前我也迷茫的很久,刚好今天找到一个很有用的方法,分享给大家! Report1_...
Herbert S. Wilf Department of Mathematics University of Pennsylvania Philadelphia, Pennsylvania
Self-generating-code.zip
母函数(Generating function)详解
一篇较好的描述seq2seq模式的英文资料。...works can be used to generate complex sequences with long-range struc- ture, simply by predicting one data point at a time. The approach is demonstrated for text ...
NULL 博文链接:https://awen7916.iteye.com/blog/2239793
We present a model that generates natural language descriptions of images and their regions. Our approach leverages datasets of images and their sentence descriptions to learn about the inter-modal ...
single-layer transmission-type metasurfaces are proposed to generate a converged vortex beam and vortex beams with different topological charges. A new metasurface design is used to generate the ...