简单的火车票售卖机制

本文通过解析火车票售卖机制,深入探讨了如何利用二维数组来模拟和管理票务库存,同时介绍了相关函数在操作数组过程中的作用,帮助读者更好地理解和运用这种数据结构在实际问题中的解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<string.h>
#include <stdlib.h>//知识点:二维数组,字符串比较函数 
int main()
{
    int seats[16][6];
    int i,j,sold;
    char word[5];
    char name[20];
    printf("What's your name?\n");
    scanf("%s",&name);
    for(i=0;i<16;i++)
    {

        for(j=0;j<6;j++)
        {
            seats[i][j]=1;
        }
    }

    printf("Welcome to use %s's railway auto-ticketing record system\n",name);
    printf("Please input:\n");

    while(1)
    {
        scanf("%s",&word);
        sold=atoi(word);
        if(strcmp(word,"exit")==0||strcmp(word,"Exit")==0)break;
        else if(strcmp(word,"check")==0||strcmp(word,"Check")==0){
            for(i=0;i<16;i++)
            {
                for(j=0;j<6;j++)
                {
                    printf("%3d",seats[i][j]);
                }
                printf("\n");
            }
        }
        else if(sold>=11&&sold<=166){
            seats[sold/10-1][sold%10-1]=0;
            for(i=0;i<16;i++)
            {
                for(j=0;j<6;j++)
                {
                    printf("%3d",seats[i][j]);
                }
                printf("\n");
            }
        }
        else printf("input error\n");
    }


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值