• 【C语言程序设计试验与习题指导】试验十三 3 [未完成]


    #include <stdio.h>
    #include <assert.h>
    #define MAX_N 10
    
    int in_car_num = 0;
    
    struct cars{
        int id;
        int in_time;
    };
    
    void come_in_car(int c_id, int c_time, int number_of_parking, struct cars *in_car, struct cars *waiting_car);
    void init_cars(struct cars *car_ptr, int num);
    int find_available_parking_index(struct cars *car_ptr);
    void pass_space(void);
    
    int main(void){
        struct cars in_car[MAX_N], waiting_car[MAX_N];
        int number_of_parking, c_id, c_time, is_break;
        char order;
        init_cars(in_car, MAX_N); init_cars(waiting_car, MAX_N);
        is_break = 0;
        scanf("%d", &number_of_parking);
        pass_space();
        while (1) {
            if (is_break) {
                break;
            }
            scanf("%c%d%d", &order, &c_id, &c_time);
            pass_space();
            switch (order) {
                case 'A':
                    come_in_car(c_id, c_time, number_of_parking, in_car, waiting_car);
                    break;
                case 'D':
                    ;
                    break;
                case 'E':
                    is_break = 1;
                    break;
                default:
                    printf("你的输入命令有错
    ");
                    break;
            }
            
        }
        
        return 0;
    }
    
    void pass_space(void){
        while (getchar()!= '
    ');
    }
    
    /* 初始化车辆信息 */
    void init_cars(struct cars *car_ptr, int num){
        for (; num > 0; num--) {
            car_ptr->id = -1;
            car_ptr++;
        }
    }
    
    /* 查找可用的车位索引*/
    int find_available_parking_index(struct cars *car_ptr){
        int i;
        for (i = 0; i < MAX_N; i++) {
            if (car_ptr->id == -1){
                return i;
            }
            car_ptr++;
        }
        assert(0);
        return 0;
    }
    
    
    /* 停车等级信息处理 */
    void come_in_car(int c_id, int c_time, int number_of_parking, struct cars *in_car, struct cars *waiting_car){
        int c_index;
        if (in_car_num < number_of_parking) {
            c_index = find_available_parking_index(in_car);
            in_car[c_index].id = c_id;
            in_car[c_index].in_time = c_time;
            in_car_num++;
            printf("%d号车停入%d号位
    ", c_id, c_index+1);
        }else{
            printf("%d号车在变道上等待
    ", c_id);
            c_index = find_available_parking_index(waiting_car);
            waiting_car[c_index].id = c_id;
        }
    }
  • 相关阅读:
    sharepoint无法到搜索人员
    sharepoint 自定义操作 CustomAction
    sharepoint 自定列表总结
    向数据表中插入字符序号,例如"001""002"
    通过sharepoint 客户脚本,验证列表添加页面上的时间
    WebService入门(1)
    Java虚拟机1:什么是Java
    SFTP服务搭建
    Shell学习——特殊变量
    js知识点~扁平数据结构转Tree
  • 原文地址:https://www.cnblogs.com/sidianok/p/15387452.html
Copyright © 2020-2023  润新知