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 ccnuteam4 at 2008-08-21 18:05:27 on Problem 2681
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int n,m,i,j,k,num;
	scanf("%d",&n);
	getchar();
	int **count;
    char **str;
	count=(int **)malloc(2*n*sizeof(int *));
	str=(char **)malloc(2*n*sizeof(char *));
	for(i=0;i<2*n;i++)
	{
		count[i]=(int *)malloc(26*sizeof(int));
		str[i]=(char *)malloc(50*sizeof(char));
		memset(count[i],0,26*sizeof(int));
	}
	for(i=0;i<2*n;i++)
	{
		j=0;
		scanf("%c",str[i]+j);
		while(str[i][j]!='\n')
		{
			count[i][str[i][j]-97]++;
			j++;
			scanf("%c",str[i]+j);
		}
	}
	for(i=0,k=1;i<2*n-1;i+=2)
	{
		num=0;
		for(j=0;j<26;j++)
		{
			m=count[i][j]-count[i+1][j];
			if(m==0)
				continue;
			num+=abs(m);
		}
		printf("Case #%d:  %d\n",k,num);
		k++;
	}
	for(i=0;i<2*n;i++)
	{
		free(count[i]);
        free(str[i]);
	}
	free(count);
	free(str);
        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