正文

保龄球计分统计2009-04-27 22:32:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bigpig/42594.html

分享到:

#include<stdio.h>#include<stdlib.h>struct strike{ int frist; int second; struct strike *next;};struct strike *creat(void){ struct strike *head; struct strike *p,*q; int i; /*if(head) {  free(head); }*/ p=head=(struct strike *)malloc(sizeof(struct strike)); head->frist=head->second=0; for(i=1;i<=10;i++) {  q=(struct strike *)malloc(sizeof(struct strike));  q->frist=0;q->second=0;  p->next=q;  p=q; } p->next=NULL; if(!head) {  printf("error");  exit(1); } return head;}int setScore(struct strike *head){ int i; struct strike *p; p=head; for(i=0;i<11&&p!=NULL;i++) {  printf("请输入第%d次击倒的瓶子数:",i+1);  scanf("%d",&p->frist);  getchar();  printf("%d次的分数:%d\n",i+1,p->frist);  printf("\n");  if(i==9)  {   if(p->frist==10)   {    p=p->next;    i++;    printf("\n请输入第%d次击倒的瓶子数(您可以输入两次):",i+1);    scanf("%d",&p->frist);    getchar();    scanf("%d",&p->second);    printf("测试");    getchar();    return i+1;   }   else   {    printf("\n您可以补输一次:");    scanf("%d",&p->second);    getchar();    if((p->frist+p->second==10)&&(p->second!=0))    {     p=p->next;     i++;     printf("\n您被嘉奖一次,请输入:");     scanf("%d",&p->frist);     getchar();     return i+1;    }    else    {     return i+1;    }   }  }  else  {   if(p->frist==10)   {    p=p->next;   }   else   {    printf("\n您可以在击一次:");    scanf("%d",&p->second);    p=p->next;   }  }  } //return 0;}int getScore(struct strike *head){ int i,num; int sum=0; struct strike *p; p=head; num=setScore(head); printf("sum=%d",sum); for(i=0;i<num&&p->next!=NULL;i++) {  if(p->frist+p->second<10)  {   //printf("***%d***",sum);   sum=sum+p->frist+p->second;   p=p->next;  }  else if((p->frist==10)&&(p->second==0))  {   sum=sum+p->frist;   sum=sum+p->next->frist+p->next->second;   p=p->next;            printf("***%d***sum=%d",p->frist,sum);  }  else if((p->frist+p->second==10)&&(p->second!=0))  {   sum=sum+p->frist+p->second;   sum=sum+p->next->frist;   p=p->next;  }  else  {   printf("error");   exit(1);  } } printf("击球的次数为:%d,获得的分数为:%d",num,sum); return sum;}int main(){ struct strike *head; int num; int sum; head = creat(); //num=setScore(head); sum=getScore(head); //printf("击球的次数为:%d,获得的分数为:%d",num,sum); printf("获得的分数为:%d",sum); return 0;}

阅读(1244) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册