zoukankan      html  css  js  c++  java
  • 【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;
        }
    }
  • 相关阅读:
    六:页面优化
    五:title,keywords,description标签
    专题之一:开篇有益
    通过JavaScript以及ActiveX控件获得客户端的机器名[Z]
    [1]Web Service简介
    (转载)虚拟环境中的隐蔽信道(续)
    虚拟机VMware如何能将屏幕调大
    VMware下Ubuntu上网设置
    基于CPU负载的隐蔽信道 ——> ——>基于网络负载的隐蔽信道
    Ubuntu 12.04终端Terminal快捷方式调用
  • 原文地址:https://www.cnblogs.com/sidianok/p/15387452.html
Copyright © 2011-2022 走看看