January 13, 2008

DS上機考(題目一未完

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct state_structure//結構宣告
{
char state[10];//state
char statement[128];//敘述
char choices[5][128];//選項
struct state_structure *way[5];//選項鏈結
};
void main()
{
int i,failtime=0,burgar[3],j;//計數,當掉次數,漢堡,計數
struct state_structure *head;//start指標
struct state_structure *next;
struct state_structure *fail;//fail指標
struct state_structure *asleep;//asleep指標
struct state_structure *in_test;//in_test指標
struct state_structure *food;//food指標
struct state_structure *eyes_open;//eyes-OPEN指標
struct state_structure *tomorrow;//tomorrow指標
struct state_structure *now;
struct state_structure *operate;//運算中的指標
fail=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*fail).state,"fail");//state命名
asleep=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*asleep).state,"asleep");//state命名
head=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*head).state,"start");//state命名
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
for(i=5;i>0;i--)
head->way[i]=next;//指向eye_open
for(i=0;i<3;i++)<br /> burgar[i]=0;//漢堡歸零
eyes_open=now=next;//eyeopen
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*now).state,"eyes_open");//state命名
now->way[4]=now;//不動
now->way[3]=now;
now->way[2]=fail;//當掉
now->way[1]=next;//wokeup
now=next;//woke_up
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*now).state,"woke_up");//state命名
now->way[4]=now;//不動
now->way[3]=now;
now->way[2]=fail;//當掉
now->way[1]=next;//breakfast
now=next;//breakfast
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*now).state,"breakfast");//state命名
now->way[4]=now;//不動
now->way[3]=now;
now->way[2]=asleep;//asleep
now->way[1]=next;//in_test
in_test=now=next;//in_test
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*now).state,"in_test");//state命名
now->way[4]=now;//不動
now->way[3]=now;
now->way[2]=fail;//當掉
now->way[1]=next;//food
food=now=next;//food
next=(struct state_structure *)malloc(sizeof(struct state_structure));//配置記憶體
strcpy((*now).state,"food");//state命名
now->way[4]=now;//不動
now->way[3]=next;//tomorrow
now->way[2]=next;
now->way[1]=next;
tomorrow=now=next;//tomorrow
//next=(struct state_structure *)malloc(sizeof(struct state_structure));
strcpy((*now).state,"tomorrow");//state命名
now->way[4]=now;//不動
now->way[3]=eyes_open;//eyes_open
now->way[2]=fail;//當掉
now->way[1]=food;//food
fail->way[1]=eyes_open;//fail
fail->way[2]=fail;//當掉
fail->way[3]=fail;
fail->way[4]=fail;
asleep->way[1]=in_test;//asleep
asleep->way[2]=fail;//當掉
asleep->way[3]=asleep;//asleep
asleep->way[4]=asleep;

operate=head;//運算指向開始
while(j)
{
printf("%s\n",operate->state);//印出狀態
scanf("%d",&j);//輸入選項
operate=operate->way[j];//連結選項
if(operate==fail)//當掉時,次數+1
failtime++;
else if(operate==tomorrow)//計算漢堡
burgar[j-1]++;
}
i=failtime%2;//依此奇數偶數來判斷上下學期
j=failtime/2;//每兩學期為一年
printf("\n現在是大%d",j+2);
if(i==0)
printf("上學期\n");
else
printf("下學期\n");
printf("總共吃了:\n");
printf("大麥克: %d個\n",burgar[0]);
printf("一品燒穀堡:%d個\n",burgar[1]);
printf("勁辣雞腿堡:%d個\n",burgar[2]);

}

0推薦此文章
Today's Visitors: 0 Total Visitors: 5
Personal Category: Uncategorized Articles Topic: technology
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0