九度OJ 1066 字符串排序
2014-01-25 12:58
435 查看
题目地址:http://ac.jobdu.com/problem.php?pid=1066
题目描述:
输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出排序后的结果
输入:
一个字符串,其长度n<=20
输出:
输入样例可能有多组,对于每组测试样例,
按照ASCII码的大小对输入的字符串从小到大进行排序,输出排序后的结果
样例输入:
样例输出:
题目描述:
输入一个长度不超过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\n", input); while (getchar() != '\n') continue; } return 0; }
相关文章推荐
- 九度OJ 1066 字符串排序
- 九度 OJ 1066:字符串排序
- 九度oj 题目1066:字符串排序
- 九度OJ 1066 清华01机试题之字符串排序
- 九度OJ 1066:字符串排序 (排序)
- 九度OJ 1066 字符串排序
- 九度OJ 题目1066:字符串排序
- 九度OJ题目1054:字符串内排序
- 【剑指offer】【九度oj】字符串的排序
- 九度oj-字符串后缀排序
- 九度OJ 题目1135:字符串排序
- 九度OJ 1135:字符串排序 (排序)
- 九度OJ 1135:字符串排序 (排序)
- 九度 Online Judge 算法 刷题 题目1066:字符串排序
- 【九度OJ】题目1054:字符串内排序 解题报告
- 九度oj-1135-字符串排序
- 九度OJ 1054:字符串内排序 (排序)
- 九度OJ 1054:字符串内排序 (排序)
- [九度OJ]1431.Sort(寻找前m大数并排序)
- 【九度OJ】1202:排序