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
直接调用库函数next_permutation,在调用前要用qsort先排序下
#define RUN #ifdef RUN #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <vector> #include <list> #include <cctype> #include <algorithm> #include <utility> #include <math.h> #include <ctime> using namespace std; #define MAXN 110 char buf[MAXN]; int cmp( const void *a , const void *b ) { return *(char *)a - *(char *)b; } int main(){ #ifndef ONLINE_JUDGE freopen("10098.in", "r", stdin); freopen("out.out", "w", stdout); #endif int n; scanf("%d", &n); while(n--){ memset(buf, 0, sizeof(buf)); scanf("%s", buf); qsort(buf, strlen(buf), sizeof(buf[0]), cmp); do { printf("%s\n", buf); } while ( next_permutation(buf, buf+strlen(buf)) ); printf("\n"); } } #endif
相关推荐
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 ...
Self-generating-code.zip
GROK-FPGA- GENERATING REAL ON-CHIP KNOWLEDGE FOR FPGA FINE-GRAIN DELAYS USING TIMING EXTRACTION
eu-16-Wen-Use-After-Use-After-Free-Exploit-UAF-By-Generating-Your-Own 安全开发 安全分析 安全体系 数据安全 安全架构
关于泊松点过程的生成方法-Generating Homogeneous Poisson Processes - PDF.pdf 在百度上看很多人问平面内泊松点怎么生成,以前我也迷茫的很久,刚好今天找到一个很有用的方法,分享给大家! Report1_...
PERFORMANCE PROTOTYPING - GENERATING AND SIMULATING A DISTRIBUTED IT-SYSTEM FROM UML MODELS.pdf
Introduction to Probability,Variance, covariance, correlation, moment-generating functions。概率论中的方差协方差相关等概念解析。
Herbert S. Wilf Department of Mathematics University of Pennsylvania Philadelphia, Pennsylvania
notes-generating-appp
diagnosis-generating2
Episode-Based Prototype Generating Network for Zero-Shot Learning.pdf
Tom Copeland - Generating Parsers with JavaCC-Centennial Books (2009)
我是来自尼日利亚的Chukwuemeka Egbuchulam,一位致力于数据的科学家,他喜欢通过数据洞察力构建模型和创建解决方案 数据科学家和机器学习科学家 在提出想法和提出特定问题的解决方案时,我至关重要。...
WC Yeh-universal generating MPs
A Segmentation Method for Lung Parenchyma Image Sequences Based on Superpixels and a Self-Generating Neural Forest
Cavitary nodule segmentation in computed tomography images based on self-generating neural networks and particle swarm optimization
GAN用于生成MNIST图像
Generating Adversarial Example”的对应代码。 Tensorflow 中三种攻击算法的实现。 它在 Python 3.6 和 matlab 2018b 上正确运行。 model.image_size:图像大小(例如,MNIST 为 28,CIFAR 为 32) model.num_...
IntelliJ测试生成插件
视频图matlab代码自主2D地图生成机器人 这款自主的2D地图生成机器人是为在Carleton大学进行的ELEC 3907第三年开放式项目课程而创建的。 该项目是由6位热衷于设计和从事项目工作的个人创建的。 该机器人的工作方式是...