| ||||||||||
| 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 | |||||||||
我是新手,请帮忙看看代码,是不是因为循环太多超时的?谢谢!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator