📄 yl5.c
字号:
/* Note:Your choice is C IDE */
#include "stdio.h"
#define size 11
//开始进入主程序进行主要问题的研究
void main()
{
static int seat[size]={0};
int seatlevel=0;
int seatnumber=0;
int count=0;//数组元素个数计数器
int neednum=0;//需要定的票数
int lefttickets=0;//检查还有几个空座计数器
int i=0;//检查订票系统就是座位数组中还是空位即0的最小下标值。
int j=0;
int k=0;
int m=0;//检查订票系统经济舱就是座位数组中6-10还是不是有空位即0的最小下标值
int differ=0;
int p=0;//一等舱票计数器
int q=0;//经济舱票计数器
int r=0;
int s=0;
static int minnum1=0;//座位数组中一等舱空位子的最小下标,这是为输出票面座号来准备的。
static int minnum2=0;//座位数组中经济舱空位子的最小下标,这是为输出票面座号来准备的。
char want;
char y=0,n=0;
//开始处理问题程序块
printf("please type 1 for first Class \n");
printf("please type 2 for economy \n");
scanf("%d\n",&seatlevel);
scanf("%d\n",&neednum);
printf("you book grade %d \n",seatlevel);
printf("you need %d tickets\n",neednum);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//以下是头等舱处理程序
if(seatlevel==1)
{
for(seatnumber=1;seatnumber<=5;seatnumber++)
{
if(seat[seatnumber]==0)
{
lefttickets++;
//printf("thanks for your booking,your registe information is :\n""first Class,seatnumber is %d\n",seatnumber);
//seat[seatnumber]=1;
//break;
}
}
///////////////////////////////////////////////////////////
printf("we have %d tickets left\n",lefttickets);
if(neednum<=lefttickets)
{
for(i=1;i<=5;i++)
{
if(seat[i]==0)
{
minnum1=i;//在本程序中,默认机票是由先来后到的顺序输出的,
//也就是只要知道了空座位的最小下标,通过lefttickets就可以计算出应该输出的是哪张票或者哪几张票了。
break;
}
}
//////////////////////////////////////////////////////
for(j=minnum1;j<=(minnum1+neednum-1);j++)
{
printf("thanks for your booking,your register information is :\n""first Class,seatnumber is %d\n",j);
seat[j]=1;
}
}
//////////////////////////////////////////////////////////
if(neednum>lefttickets)
{
printf("we have not enought first Class tickets left for you !\n"
"would you like to book %d economy tickets instead of first Class tickets\n "
"if you want to,please key y,if you don't want,please key n\n",(neednum-lefttickets));
}
scanf("%c",&want);
///////////////////////////////////////////////////////////
if(want==y)
{
for(p=minnum1;p<=5;p++)//首先把一等舱的票模拟输出
{
printf("thanks for your booking,your register information is :\n""first Class,seatnumber is %d\n",p);//这就是模拟真实的机票
seat[p]=1;
}
///////////////////////////////////////////////////////
for(k=6;k<=10;k++)
{
if(seat[k]==0)
{
minnum2=k;//在本程序中,默认机票是由先来后到的顺序输出的
break;
}
}///////////////////////////////////////////////////////////////
differ=(10-minnum2+1)-(neednum-lefttickets);
if(differ>=0)//在经济舱票充足的情况下,把经济舱的票模拟输出
{
printf("we have enough economy tickets for you!");
for(q=minnum2;q<=(minnum2+(neednum-lefttickets)-1);q++)
{
printf("thanks for your booking,your registe information is :\n""economy,seatnumber is %d\n",q);//这就是模拟真实的机票
seat[q]=1;
}
}///////////////////////////////////////////////////
if(differ<0)//说明经济舱票数也还是不够乘客的需求量
{
printf("we have not enough economy tickets for you!\n"
"do you want to book %d tickets ? and the left tickets have to wait for the next flight!\n"
"if you want,please key y,if you don't want,please key n \n",(lefttickets+(5-minnum2+1)));
if(want==y)
{
for(r=minnum1;r<=5;r++)
{
printf("thanks for your booking,your registe information is :\n""first Class,seatnumber is %d\n",r);//这就是模拟真实的机票
seat[r]=1;
}
for(s=minnum2;s<=10;s++)
{
printf("thanks for your booking,your registe information is :\n""economy,seatnumber is %d\n",s);//这就是模拟真实的机票
seat[s]=1;
}
}
/////////////////////////////////////////////////////////
if(want==n)
{
printf("soory!please wait for the next flight,it leaves in 3 hours!\n"
"have a good time!");
}
}
}
/////////////////////////////////////////////////////////////////
if(want==n)
{
printf("soory!please wait for the next flight,it leaves in 3 hours!\n"
"have a good time!");
}
///////////////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//以下是经济舱处理程序
if(seatlevel==2)
{
for(seatnumber=6;seatnumber<=10;seatnumber++)
{
if(seat[seatnumber]==0)
{
lefttickets++;
//printf("thanks for your booking,your registe information is :\n""first Class,seatnumber is %d\n",seatnumber);
//seat[seatnumber]=1;
//break;
}
}
///////////////////////////////////////////////////////////
printf("we have %d tickets left\n",lefttickets);
if(neednum<=lefttickets)
{
for(i=6;i<=10;i++)
{
if(seat[i]==0)
{
minnum1=i;//在本程序中,默认机票是由先来后到的顺序输出的,
//也就是只要知道了空座位的最小下标,通过lefttickets就可以计算出应该输出的是哪张票或者哪几张票了。
break;
}
}
//////////////////////////////////////////////////////
for(j=minnum1;j<=(minnum1+neednum-1);j++)
{
printf("thanks for your booking,your register information is :\n""economy,seatnumber is %d\n",j);
seat[j]=1;
}
}
//////////////////////////////////////////////////////////
if(neednum>lefttickets)
{
printf("we have not enought economy tickets left for you !\n"
"would you like to book %d first Class tickets instead of economy tickets\n "
"if you want to,please key y,if you don't want,please key n\n",(neednum-lefttickets));
}
scanf("%c",&want);
///////////////////////////////////////////////////////////
if(want==y)
{
for(p=minnum1;p<=10;p++)//首先把经济舱的票模拟输出
{
printf("thanks for your booking,your register information is :\n""economy,seatnumber is %d\n",p);//这就是模拟真实的机票
seat[p]=1;
}
///////////////////////////////////////////////////////
for(k=1;k<=5;k++)
{
if(seat[k]==0)
{
minnum2=k;//在本程序中,默认机票是由先来后到的顺序输出的
break;
}
}///////////////////////////////////////////////////////////////
differ=(5-minnum2+1)-(neednum-lefttickets);
if(differ>=0)//在一等舱票充足的情况下,把一等舱的票模拟输出
{
printf("we have enough economy tickets for you!");
for(q=minnum2;q<=(minnum2+(neednum-lefttickets)-1);q++)
{
printf("thanks for your booking,your registe information is :\n""first Class,seatnumber is %d\n",q);//这就是模拟真实的机票
seat[q]=1;
}
}///////////////////////////////////////////////////
if(differ<0)//说明一等舱票数也还是不够乘客的需求量
{
printf("we have not enough first Class tickets for you!\n"
"do you want to book %d tickets ? and the left tickets have to wait for the next flight!\n"
"if you want,please key y,if you don't want,please key n \n",(lefttickets+(5-minnum2+1)));
if(want==y)
{
for(r=minnum1;r<=10;r++)
{
printf("thanks for your booking,your registe information is :\n""economy,seatnumber is %d\n",r);//这就是模拟真实的机票
seat[r]=1;
}
for(s=minnum2;s<=5;s++)
{
printf("thanks for your booking,your registe information is :\n""first Class,seatnumber is %d\n",s);//这就是模拟真实的机票
seat[s]=1;
}
}
/////////////////////////////////////////////////////////
if(want==n)
{
printf("soory!please wait for the next flight,it leaves in 3 hours!\n"
"have a good time!");
}
}
}
/////////////////////////////////////////////////////////////////
if(want==n)
{
printf("soory!please wait for the next flight,it leaves in 3 hours!\n"
"have a good time!");
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(count=0;count<=10;count++)//输出座位数组的内容如下
{
printf("%d ", seat[count]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -