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

Re:各位帮忙看看啊!

Posted by eulerray at 2007-06-02 13:48:45 on Problem 1002
In Reply To:各位帮忙看看啊! Posted by:eulerray at 2007-06-02 13:48:14
为什么WA啊?
#include<stdio.h>
#include<string.h>

void main()
{
	int i,n,j,k,d[60000];
	char s[100]={0};
	long tran (char a[]);
	long c[120000],e[60000],temp,flag;

	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%s",s);
		c[i]=tran(s);
		memset(s,0,sizeof(s));
	}
   
	
	for(i=1;i<n;i++)
		for(j=1;j<=n-i;j++)
			if(c[j]>c[j+1]){
				temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}
     
        
		for(i=1;i<=20;i++)
			d[i]=1;
		i=1; k=1;
		while(1){
			if(i>n) break;
			flag=c[i];
			i=i+1;
			while(flag==c[i]){
				i++;
				d[k]++;
			}
			if(d[k]>1){
				e[k]=flag;
				k=k+1;
			}
		}
		
		if(d[1]==1)
			printf("No duplicates.\n");
			
		else {
		for(j=1;j<k;j++)
			printf("%03d-%04d %d\n",e[j]/10000,e[j]%10000,d[j]);
		}
   
}
long tran(char a[])
{
	int i=0,b[7],j;
	long sum;
	for(j=0;j<strlen(a);j++){
    
	if (a[j]>='0'&&a[j]<='9')
		{ b[i]=a[j]-'0';
		i++;}
    
	if (a[j]>='A'&&a[j]<='P')
		{ b[i]=(a[j]-'A')/3+2;
		i++;}

    if (a[j]>='R'&&a[j]<='Y')
		{ b[i]=(a[j]-'A'-1)/3+2;
		i++;}
	}
	sum=b[0]*1000000+b[1]*100000+b[2]*10000+b[3]*1000+b[4]*100+b[5]*10+b[5];

	return sum;
}

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