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

请大家帮忙看看为什么是output limit exceed

Posted by wronger at 2006-05-04 15:23:19 on Problem 1256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

double key(char a){
	if(a<='z'&&a>='a') return a-'a'+1;
	else return a-'A'+0.5;
}

int compare(const void *p, const void *q){
	if(key(*(char*)p)>key(*(char*)q)) return 1;
	else if(key(*(char*)p)<key(*(char*)q)) return -1;
	else return 0;
}

int n, k, t;
char s[14], pr[14];
bool use[14];

void print(){
    int i;
	if(k==0) printf("%s\n", pr);
	else{
		for(i=0; i<n; i++){
			if(!use[i]&&(i==0||s[i]!=s[i-1]||use[i-1])){
				pr[t]=s[i];
				use[i]=true;
				t++;
				k--;
				print();
				k++;
				t--;
				use[i]=false;
			}
		}
	}
}

int main(){
	int i;
	scanf("%d", &n);
	while(n--){
		scanf("%s", s);
		n=(int)strlen(s);
		for(i=0; i<n; i++)
			use[i]=false;
		qsort(s, n, sizeof(char), compare);
		t=0; pr[n]='\0';
		k=n;
		print();
	}
	return 0;
}

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