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 ACong at 2008-11-15 19:55:44 on Problem 2681
In Reply To:Re:请问这道题几十毫秒是怎么做出来的? Posted by:purplefly at 2006-07-29 22:09:01
呃,我的要125MS,很郁闷,我觉得我这个算法已经算好的了。。。
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX 26
#define M 100
int main(){
	int n,i=0,j=0;
	char c[MAX],d[MAX];
	int lena,lenb;
	char a[M];
	char b[M];
	int sum=0;
	int k;
	while(scanf("%d",&n)!=EOF && n!=0)
	{
		k=1;
		getchar();
		while(n--)
		{
			memset(c,0,sizeof(c));
			memset(d,0,sizeof(d));
			sum=0;
			gets(a);
			gets(b);
			lena=strlen(a);
			lenb=strlen(b);
			for(i=0;i<lena;i++)
				c[a[i]-'a']++;
			for(i=0;i<lenb;i++)
				d[b[i]-'a']++;
			for(i=0;i<MAX;i++)
				sum+=abs(c[i]-d[i]);
			printf("Case #%d:  %d\n",k++,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