• POJ 1731


    #include <stdio.h>
    #include <string.h>
    #define N_MAX 201
    int len;
    char buf[201];
    
    void printf_arr()
    {
    	for (int i = 0; i < len; i++) {
    		printf("%c", buf[i]);
    	}
    	printf("
    ");
    }
    
    void qsort(char *a, int begin, int end)
    {
    	if (begin >= end) return;
    	int l = begin, r = end, k = a[l];
    	while (l != r) {
    		while (l < r && k <= a[r]) r--;
    		while (l < r && k >= a[l]) l++;
    		if (l < r) {
    			int tmp = a[l];
    			a[l] = a[r];
    			a[r] = tmp;
    		}
    	}
    	a[begin] = a[l];
    	a[l] = k;
    	qsort(a, begin, l - 1);
    	qsort(a, l + 1, end);
    }
    
    int main(int argc, char* argv[])
    {
    	memset(buf, 0, sizeof(char) * 201);
    	scanf("%s", buf);
    
    	len = strlen(buf);
    
    	qsort(buf, 0, len-1);
    	len = strlen(buf);
    	printf("%s
    ", buf);
    
    	while (1)
    	{
    			int i = len-1;
    			for (; i >= 0; i--) {
    				if (buf[i] > buf[i - 1]) {
    					break;
    				}
    			}
    
    			if (i == 0) {
    				break;
    			}
    
    			int min = 'z';
    			int l = i - 1;
    			int r = i;
    			for (int j = i; j < len; j++) {
    				if (buf[j] > buf[l] && buf[j] < min) {
    					min = buf[j];
    					r = j;
    				}
    			}
    
    			int tmp = buf[l];
    			buf[l] = buf[r];
    			buf[r] = tmp;
    
    			qsort(buf, l + 1, len - 1);
    
    			printf_arr();
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    【待整理】转义字符
    关系运算符 与 逻辑运算符
    浏览器相关
    正则表达式
    样式定义——多重浏览器
    事件
    属性定义
    数组
    日期
    构造函数
  • 原文地址:https://www.cnblogs.com/jingyg/p/7723141.html
Copyright © 2020-2023  润新知