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 |
Negative numbers provided by these formulae indicate the substance's effects have worn off and should not be considered.In Reply To:我把程序贴出来,大家帮我看看是什么问题哈!谢谢! Posted by:yjn at 2005-08-01 16:24:05 > #include <stdio.h> > #include <string.h> > > > long double f; > > struct water > { > int type; //0 for chocolate and 1 for coffee > long double n; //quantity > long t; //time > }; > > water a[101],tempwater; > long q[101]; > > int na,nq,ia,iq,i,j,k,temp; > long t; > long double n; > > char *s; > int main() > { > s=new char[20]; > na=nq=0; > > > while (scanf("%s",s)!=EOF) > { > if (strcmp(s,"Query")==0) > { > scanf("%ld",&t); > q[++nq]=t; > } > if (strcmp(s,"Chocolate")==0) > { > na++; > scanf("%ld",&t); > scanf("%lf",&n); > a[na].type=0; > a[na].t=t; > a[na].n=n; > } > if (strcmp(s,"Coffee")==0) > { > na++; > scanf("%ld",&t); > scanf("%lf",&n); > > > a[na].type=1; > a[na].t=t; > a[na].n=n; > } > > }//input > > > for (i=1;i<nq;i++) > { > k=i; > for (j=i+1;j<=nq;j++) > if (q[k]>q[j]) k=j; > temp=q[k];q[k]=q[i];q[i]=temp; > > } > > > for (i=1;i<na;i++) > { > k=i; > for (j=i+1;j<=na;j++) > if (a[k].t>a[j].t) k=j; > tempwater=a[k]; > a[k]=a[i]; > a[i]=tempwater; > }//sort > > > ia=iq=1; > f=0; > for (iq=1;iq<=nq;iq++) > { > f=0; > for (ia=1;a[ia].t<=q[iq] && ia<=na;ia++) > { > t=q[iq]-a[ia].t; > if (a[ia].type==1) f+=2*a[ia].n-(long double)t*t/79; > else f+=8*a[ia].n-(long double)t/12; > } > if (f<=1.0) f=1; > printf("%ld ",q[iq]); > printf("%.1f\n",f); > } > > > > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator