zoukankan      html  css  js  c++  java
  • 九度OJ 1066 字符串排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1066

    题目描述:

     输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出排序后的结果

    输入:

     一个字符串,其长度n<=20

    输出:

     输入样例可能有多组,对于每组测试样例,

    按照ASCII码的大小对输入的字符串从小到大进行排序,输出排序后的结果
    样例输入:
    dcba
    样例输出:
    abcd
    /*
     * Main.c
     *
     *  Created on: 2014年1月25日
     *      Author: Shaobo
     */
    #include <stdio.h>
    #include <string.h>
     
    int Partition(char data[], int from, int to){
        char pivot = data[from];
        while (from < to){
            while (from < to && data[to] >= pivot) --to;
            data[from] = data[to];
            while (from < to && data[from] <= pivot) ++from;
            data[to] = data[from];
        }
        data[from] = pivot;
        return from;
    }
     
    void QuickSort(char data[], int from, int to){
        int pivotpos = Partition (data, from, to);
        if (from < pivotpos-1)
            QuickSort(data, from, pivotpos-1);
        if (to > pivotpos)
            QuickSort(data, pivotpos+1, to);
    }
     
    int main(void){
        char input[21];
        int len;
     
        while (scanf ("%s", input) != EOF){
            len = strlen(input);
            QuickSort(input, 0, len-1);
            printf ("%s
    ", input);
            while (getchar() != '
    ')
                continue;
        }
        return 0;
    }
    


  • 相关阅读:
    之前总结的,现在要找工作了,给大家分享一下
    numpy总结
    django知识分支_1
    Django小总结
    ORM
    百度在线编辑器 配置修改
    百度在线编辑器
    TP5 路由使用
    cache 订单队列
    绘制静态地图API-高德地图
  • 原文地址:https://www.cnblogs.com/liushaobo/p/4373853.html
Copyright © 2011-2022 走看看