如何加快程序运行速度
这是usaco的第一道题,提示运行时间过长,求解各位
下面是我的代码
#include<stdio.h>
#include<string.h>
#define max 10
struct person
{
char name[17];
int money;
};
typedef struct person person;
person Person[max];
int num;
//look up the name
person * lookup(char *a)
{
char i;
for(i=0;i<max;i++)
{
if(strcmp(a,Person[i].name)==0)
return &Person[i];
}
return &Person[0];
}
main()
{
FILE *fin=fopen("gift1.in","r");
FILE *fout=fopen("gift1.out","w");
fscanf(fin,"%d",&num);
//print in all the name
int i,j;
for(i=0;i<num;i++)
{
fscanf(fin,"%s",Person[i].name);
Person[i].money=0;
}
//Do with the giving and receiving
char name[17];
person *giv,*rec;
int sum,n;
for(i=0;i<num;i++)
{
fscanf(fin,"%s,%d,%d",name,&sum,&n);
if(n!=0)
{
giv=lookup(name);
(* giv).money+=sum%n;
for(j=0;j<n;j++)
{
fscanf(fin,"%s",name);
rec=lookup(name);
(* rec).money+=sum/n;
}
}
}
//show the result
for(i=0;i<num;i++)
{
fprintf(fout,"%s %d\n",Person[i].name,Person[i].money);
}
exit(0);
}
下面是我的代码
#include<stdio.h>
#include<string.h>
#define max 10
struct person
{
char name[17];
int money;
};
typedef struct person person;
person Person[max];
int num;
//look up the name
person * lookup(char *a)
{
char i;
for(i=0;i<max;i++)
{
if(strcmp(a,Person[i].name)==0)
return &Person[i];
}
return &Person[0];
}
main()
{
FILE *fin=fopen("gift1.in","r");
FILE *fout=fopen("gift1.out","w");
fscanf(fin,"%d",&num);
//print in all the name
int i,j;
for(i=0;i<num;i++)
{
fscanf(fin,"%s",Person[i].name);
Person[i].money=0;
}
//Do with the giving and receiving
char name[17];
person *giv,*rec;
int sum,n;
for(i=0;i<num;i++)
{
fscanf(fin,"%s,%d,%d",name,&sum,&n);
if(n!=0)
{
giv=lookup(name);
(* giv).money+=sum%n;
for(j=0;j<n;j++)
{
fscanf(fin,"%s",name);
rec=lookup(name);
(* rec).money+=sum/n;
}
}
}
//show the result
for(i=0;i<num;i++)
{
fprintf(fout,"%s %d\n",Person[i].name,Person[i].money);
}
exit(0);
}
...全文
相关推荐
修改注册表加快程序运行速度
通过修改注册表,加快程序运行速度 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "ConfigFileAllocSize"=dword:000001f4
不激活图表对图表内部进行修改,能加快程序运行速度
编大批量图表程序时速度是个大问题,不激活图表对图表内部进行修改,能加快程序运行速度,本表VBA代码不激活图表对图表内部进行了七处修改,对修改纵大批量图表能加快程序运行速度.
提高PLC程序运行速度的编程方法有哪些
怎样来提高PLC程序运行速度,可以采用以下几种编程方法,仅供参考。
加快程序运行:内存盘
利用大内从加快网页浏览和程序运行速度,每次关机都能释放程序运行产生的垃圾,非常使用。详细较少见里面的说明.
如何加快内存运行速度.docx
如何加快内存运行速度.docx


