UvaOJ 10098 Generating Fast, Sorted Permutation
来源:互联网 发布:centos 关闭selinux 编辑:程序博客网 时间:2024/05/20 19:46
生成“下一个排列”
思想还是参见我的这篇文章
UvaOJ 146 ID Codes
#include <stdio.h>#include <string.h>#include <stdlib.h>char s[11];int l, n;int cmp(const void* a, const void* b) {return *(char*)a - *(char*)b;}void swap(int l, int r) {char t = s[l];s[l] = s[r];s[r] = t;}void reverse(int l, int r) {for ( ; l<r ; l++, r--)swap(l, r);}int main() {scanf("%d", &l);while (l--) {int i=1, j;scanf("%s", s);n = strlen(s);qsort(s, n, sizeof(char), cmp);printf("%s\n", s);while (i) {for (i=n-1 ; i>0 ; i--)if (s[i-1] < s[i]) {for (j=i+1 ; j<n ; j++)if (s[j] <= s[i-1])break;swap(i-1, j-1);reverse(i, n-1);printf("%s\n", s);break;}}printf("\n");}}
0 0
- UvaOJ 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
- UVaOJ 10098 - Generating Fast
- UVAOJ 10098 Generating Fast
- UVa10098 Generating Fast, Sorted Permutation
- uva10098 Generating Fast, Sorted Permutation
- UVA 10098 Generating Fast, Sorted Permutation(全排列)
- UVa 10098 Generating Fast
- 10098--Generating Fast
- uva 10098 - Generating Fast
- 10098 - Generating Fast
- UVa 10098 Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- 10098 - Generating Fast
- 个人对银行知识的几点认识和理解
- C++中得拷贝构造函数
- leetcode Reverse Integer
- 资深系统管理员给Linux/Unix新人们的建议
- 温故知新--Servlet(七)--请求转发和重定向区别
- UvaOJ 10098 Generating Fast, Sorted Permutation
- HDU - 1269 迷宫城堡
- 基本套接字调用
- java 线程中断
- hdu 1159 Common Subsequence(dp)
- 简便使用jQuery(上)
- Introduction to Languages and the Theory of Computation--Chapter 1 学习笔记
- 搜索概述
- HDU - 1232 畅通工程