//若有不恰当之处,万望及时批评指正
#include<stdio.h>
#define SIZE 10
int main(void)
{
int type, chose;
int position[10] = { 1,1,1,1,1,1,1,1,1,1 };
printf("Please type 1 for \"first class\"\n");
printf("Please type 1 for \"economy\"\n");
scanf_s("%d", &type);
if (type == 1) {
for (int i = 0; i < 5; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("一等舱已满,您是否愿意调到经济舱(0/1)");
scanf_s("%d", &chose);
if (chose == 1) {
for (int i = 5; i < 10; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("本次航班座位已满,下一个航班将在3小时以后起飞。");
break;
}
}
}
else {
printf("Next flight leaves in 3 hours.");
}
break;
}
}
}
else if (type == 2) {
for (int i = 5; i < 10; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("经济舱已满,您是否愿意调到一等舱(0/1)");
scanf_s("%d", &chose);
if (chose == 1) {
for (int i = 0; i < 5; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("本次航班座位已满,下一个航班将在3小时以后起飞。");
break;
}
}
}
else {
printf("Next flight leaves in 3 hours.");
}
break;
}
}
}
else {
printf("您的输入不符合要求,请重新输入。");
}
printf("\n\n");
return 0;
#include<stdio.h>
#define SIZE 10
int main(void)
{
int type, chose;
int position[10] = { 1,1,1,1,1,1,1,1,1,1 };
printf("Please type 1 for \"first class\"\n");
printf("Please type 1 for \"economy\"\n");
scanf_s("%d", &type);
if (type == 1) {
for (int i = 0; i < 5; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("一等舱已满,您是否愿意调到经济舱(0/1)");
scanf_s("%d", &chose);
if (chose == 1) {
for (int i = 5; i < 10; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("本次航班座位已满,下一个航班将在3小时以后起飞。");
break;
}
}
}
else {
printf("Next flight leaves in 3 hours.");
}
break;
}
}
}
else if (type == 2) {
for (int i = 5; i < 10; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("经济舱已满,您是否愿意调到一等舱(0/1)");
scanf_s("%d", &chose);
if (chose == 1) {
for (int i = 0; i < 5; i++) {
if (!position[i]) {
position[i] = 1;
printf("已经为您成功抢到了座位,座位号为:%d\n", i + 1);
break;
}
else {
printf("本次航班座位已满,下一个航班将在3小时以后起飞。");
break;
}
}
}
else {
printf("Next flight leaves in 3 hours.");
}
break;
}
}
}
else {
printf("您的输入不符合要求,请重新输入。");
}
printf("\n\n");
return 0;
}