Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不用stl,请问这样写哪里错了?求字符数组直接后继这个应该没问题..

Posted by 1050310209 at 2007-03-16 19:55:22 on Problem 1731
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator