| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:请问这道题几十毫秒是怎么做出来的?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator