UVa10098 Generating Fast, Sorted Permutation
2013-07-18 16:17
309 查看
Problem C
[b]Generating Fast, Sorted Permutation[/b]
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
Shahriar Manzoor
这题也确实没有什么好说的,简单的全排列题目,next_permutation()真的挺好用的。
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 20;
char s
;
int main(){
int n;
cin >> n;
while (n--){
memset(s,0,sizeof(s));
cin >> s;
int len = strlen(s);
sort(s,s+len);
cout << s << endl;
while (next_permutation(s,s+len)){
cout << s << endl;
}
cout << endl;
}
return 0;
}
[b]Generating Fast, Sorted Permutation[/b]
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
Shahriar Manzoor
这题也确实没有什么好说的,简单的全排列题目,next_permutation()真的挺好用的。
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 20;
char s
;
int main(){
int n;
cin >> n;
while (n--){
memset(s,0,sizeof(s));
cin >> s;
int len = strlen(s);
sort(s,s+len);
cout << s << endl;
while (next_permutation(s,s+len)){
cout << s << endl;
}
cout << endl;
}
return 0;
}
相关文章推荐
- uva10098 Generating Fast, Sorted Permutation
- uva 10098 Generating Fast, Sorted Permutation
- uva GeneratingFastSortedPermutation 10098
- UVA 10098 Generating Fast, Sorted Permutation(全排列)
- Generating Fast, Sorted Permutation
- Generating Fast, Sorted Permutation
- UVA 10098 Generating Fast, Sorted Permutation
- uva--10098--Generating Fast, Sorted Permutation
- UVA10098 Generating Fast【全排列】
- uva10098 - Generating Fast(快速生成有序排列)
- uva10098 Generating Fast, Sorted Permutation
- uva 10098 Generating Fast(全排列)
- UVa 10098 Generating Fast (全排列生成)
- UVA 10098 Generating Fast 解题报告
- Get indices for sorted permutation of an array in Ruby?
- UVA - 10098 - Generating Fast(全排列)
- uva-10098-Generating Fast-全排列典例
- (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)
- 浙工大姗姗杯round1 E - Generating Fast UVA - 10098
- (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)