Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不用stl,请问这样写哪里错了?求字符数组直接后继这个应该没问题..#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char str[1024], c; int foo(int len)//foo函数从str最后一个字符往前找,找到比它小的字符,交换,然后把后边的字符由小到大排序; { int i, j; for(i = len - 1; i >= 0; i--) for(j = i - 1; j >= 0; j--) { if(str[i] > str[j]) { c = str[i]; str[i] = str[j]; str[j] = c; sort(str+j+1, str+len); return 1; } } return 0; } int main() { int len; scanf("%s", str); { len = strlen(str); sort(str, str+len); //开始对字符数组排序 printf("%s\n", str); while(foo(len)) printf("%s\n", str); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator