uva10098 Generating Fast, Sorted Permutation

#include"iostream"
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"stdlib.h"
using namespace std;
char s[100];
int main()
{
int t;
cin>>t;
getchar();
while(t--)
{
scanf("%s",s);
sort(s,s+strlen(s));//所有可能情况,故要先按从小到大排序
do
{
cout<<s<<endl;
}while(next_permutation(s,s+strlen(s)));
cout<<endl;//每一个输出后都有空行,不是每两个输出之间
}
return 0;
}

时间: 2024-11-06 08:44:24

uva10098 Generating Fast, Sorted Permutation的相关文章

UVA - 10098 - Generating Fast (枚举排列)

思路:生成全排列,用next_permutation,注意生成之前先对那个字符数组排序. AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; char str[20]; int main() { int n; cin >> n; while(n-

uva 10098 Generating Fast(全排列)

还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style="font-family:Courier New;font-size:18px;">#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using

Generating Fast UVA 10098

说说: 这道题的其实就是给你一个字符串,然后输出该字符串所含字符能构成的全部的串,并按字典升序输出.解法的话,无非就是递归实现.先将原字符串排序,然后逐一确定每个位置上的字符.为了防止有重复的字符串出现,每个位置上的字符不能与之前相同.具体的解释请参见刘汝佳的<算法竞赛入门经典>P118,生成可重集的排列. 源代码: #include <stdio.h> #include <string.h> #define MAX 10+5 char s[MAX]; char p[M

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

SSTable and Log Structured Storage: LevelDB

If Protocol Buffers is the lingua franca of individual data record at Google, then the Sorted String Table (SSTable) is one of the most popular outputs for storing, processing, and exchanging datasets. As the name itself implies, an SSTable is a simp

The Hamming Distance Problem UVA 729 (01串的全排列)

说说: 这题的意思就是给你一个01串的总长度和其中1的个数,要你求出该串的所有排列,并按照字典升序输出.其实这道题和前一道Generating Fast是非常类似的,甚至更为简单.要做的就是一个DFS给每个位分配位置,若0没有用完,则先分配0.1没有用完,则接着分配1.最后将结果输出即可. 源代码: #include <stdio.h> #define MAX 16+5 int N,H,onum,znum; char p[MAX]; void dfs(int,int,int); int mai

31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replaceme

Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replaceme

LeetCode 31. Next Permutation

Problem: https://leetcode.com/problems/next-permutation/ Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest poss