uva 10098 - Generating Fast
来源:互联网 发布:linux开启smb服务 编辑:程序博客网 时间:2024/05/17 04:17
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
3ab
abc
bca
Sample Output
ab
ba
abc
acb
bac
bca
cab
cba
abc
acb
bac
bca
cab
cba
全排列
#include <stdio.h>#include <string.h>char s[100],ch;void sort(int x,int y){int i,j; for (i=x;i<y;i++) for (j=i+1;j<=y;j++) if (s[i]>s[j]) {ch=s[i];s[i]=s[j];s[j]=ch;};}int main(){int t,l,i,j,pos,min; scanf("%d\n",&t); while (t--) { gets(s); l=strlen(s); sort(0,l-1); puts(s); while (l) {pos=l-1; while ((pos>0)&&(s[pos]<=s[pos-1])) --pos; if (pos) {min=pos; for (i=pos+1;i<l;i++) if ((s[i]<s[min])&&(s[i]>s[pos-1])) min=i; ch=s[pos-1];s[pos-1]=s[min];s[min]=ch; sort(pos,l-1); puts(s); } else break; } printf("\n"); } return 0;}
- UVa 10098 Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- UVa 10098 Generating Fast
- Uva 10098 - Generating Fast
- UVA 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098: Generating Fast
- uva 10098 Generating Fast
- uva - 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- Discuz 。net版下载地址:
- FileZilla Server搭建
- C语言的那些小秘密——字节对齐
- 输入外挂
- 工作中需要注意的15个问题。
- uva 10098 - Generating Fast
- poj_2513 Colored Sticks
- C语言的那些小秘密——动态数组
- QSingleApplication类
- C++中vector的clear方法对于内存的释放方法
- 牛排生熟程度 英语说法
- C语言的那些小秘密——断言
- poj_2560 Freckles
- C语言的那些小秘密——const修饰符