回复 9楼 TonyDeng
//6515767 zy15767 AiLi
#include<stdio.h>
#include<stdlib.h>
#define trainsta 9
int main(void)
{
int a;
do
{
printf("1£©Book ticket(s):/n");
printf("2£©List available tickets:/n");
printf("3) Quit/n");
printf("Enter option: /n");
scanf("%d",&a);
if (a==1)
{
int b,c,d;
char distance[trainsta][9]={0};
distance[0][1]=155,distance[0][5]=380,
distance[1][0]=155,distance[1][3]=210,distance[1][4]=180,distance[1][7]=180,distance[1][8]=280;
distance[2][3]=95,distance[2][4]=90;
distance[3][1]=210,distance[3][2]=95,distance[3][8]=130;
distance[4][1]=180,distance[4][2]=90;
distance[5][0]=380,distance[5][6]=610;
distance[6][5]=610,distance[6][7]=235;
distance[7][1]=180,distance[7][6]=235;
distance[8][1]=280,distance[8][3]=130;
char tickets[trainsta][9]={-1};
tickets[0][1]=10,tickets[0][5]=10,
tickets[1][0]=10,tickets[1][3]=10,tickets[1][4]=10,tickets[1][7]=10,tickets[1][8]=10;
tickets[2][3]=10,tickets[2][4]=10;
tickets[3][1]=10,tickets[3][2]=10,tickets[3][8]=10;
tickets[4][1]=10,tickets[4][2]=10;
tickets[5][0]=10,tickets[5][6]=10;
tickets[6][5]=10,tickets[6][7]=10;
tickets[7][1]=10,tickets[7][6]=10;
tickets[8][1]=10,tickets[8][3]=10;
char stations[9][8]={"Ningbo","Hangzhou","Suzhou","Changzhou","Shanghai","Taizhou","Wenzhou","Jinhua","Nanjing""null"};
printf("Num/tStation/n");
int i;
for(i=0;i<10;i++)
{
printf("%d/t%s/n",i+1,station[i]);
}
printf("Origin station: /n");
scanf("%d",&b);
if (b<1)
{
printf("Invalid station number./n");
}
else if (b>9)
{printf("Invalid station number./n");
}
printf("Destination station number:/n");
scanf("%d",&c);
if (c<1)
{
printf("Invalid station number./n");
}
else if (c>9)
{printf("Invalid station number./n");
}
else if (c==b)
{
printf("No train between %s and %s/n",stations[c-1],stations[c-1]);
}
else if(distance[b][c]==0)
{
printf("No train between %s and %s/n",stations[b-1],stations[c-1]);
}
printf("Number of tickets: /n");
scanf("%d",&d);
if (d<0)
{
printf("Invalid number of tickets./n");
}
else if (d>tickets[b-1][c-1])
{
printf("Not enough tickets available (%d requested,%d remaining)./n",d,tickets[b-1][c-1]);
}
if(distance[b-1][c-1]>500)
{
printf("Tickets booked, total cost is %d RMB./n",300*d);
}
else if(distance[b-1][c-1]<500&&distance[b-1][c-1]>250)
{
printf("Tickets booked, total cost is %d RMB./n",200*d);
}