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

哪位大牛给看看?我实在是找不出错在哪里。本代码已通过题目中的范例输入数据。

Posted by hepeng at 2008-03-17 18:00:58 on Problem 1256
#include<stdio.h>
#include<string.h>
#include <iostream>
#include <algorithm>
using namespace std;
void init(int letter[52])
{
	for(int i=0;i<52;i++)
		letter[i]=0;
}


void statistic(int letter[52],char input[13])
{
	for(int i=0;i<strlen(input);i++)//去除最后一个回车
	{
		if(input[i]<='Z')
			letter[(input[i]-'A')*2]++;
		else
			letter[(input[i]-'a')*2+1]++;
	}
}

void sort(char input[])
{
	int j=0;
	int letter[52];
	init(letter);
	statistic(letter,input);

	for(int i=0;i<52;i++)
	{
		while(true)
		{
			if(letter[i]!=0&&i%2==0)
			{
				input[j++]=i/2+'A';
				letter[i]--;
			}
			else if(letter[i]!=0&&i%2==1)
			{
				input[j++]=i/2+'a';
				letter[i]--;
			}
			else
				break;
		}
	}
}

main()
{
	char input[13];
	char y[13];
	int i,j;
	int test;
	scanf("%d",&test);
	getchar();
	for(i=0;i<test;i++)
	{
		gets(input);
		sort(input);
		puts(input);
		
		strcpy(y,input);
		while(next_permutation(input,input+strlen(input)))
        {
			
			if(strcmp(input,y)!=0)
				puts(input);
			strcpy(y,input);
         }
	}
}

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