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 |
在linux下gcc编译后运行没问题呀,为什么系统wrong answer呢?include <stdio.h> #include <malloc.h> struct times { float n; struct times * next; }; int main() { float calculate(float); int i; //count the input numbers int j; int result; struct times * head,* p1,* p2,* p; p1=p2=(struct times *)malloc(sizeof(struct times)); scanf("%f",&p1->n); while(getchar()!='\n'); i=1; while((p1->n)!=0.00) { if(i==1) { head=p1; } else { p2->next=p1; p2=p1; p1=(struct times *)malloc(sizeof(struct times)); scanf("%f",&p1->n); while(getchar()!='\n'); } i++; } free(p1); p2->next=NULL; i=i-1; for(j=1;j<i;j++) { if(j==1) { p=head; result=calculate(p->n); printf("%d card(s)\n",result); } else { p=p->next; result=calculate(p->n); printf("%d card(s)\n",result); } } return 0; } float calculate(float n) { float s,k=1; //k木板数 if(n<=0.5) return 1; else { while(s<=n) { s=s+1/(k+1); k++; } return (int)(k-1); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator