zoukankan      html  css  js  c++  java
  • 第二次作业

    include

    using namespace std;

    bool Undercart_UP=1,Undercart_DOWN=0;
    bool green=1,red=0;
    bool carIn = false, carOut = false;
    bool light = red;
    bool Undercart= Undercart_DOWN;

    bool switchUndercartUp()
    {
    cout << "......杆上升......" << endl;
    Undercart=Undercart_UP ;
    return Undercart;
    }

    bool switchUndercartDOWN()
    {
    cout << "......杆下降......" << endl;
    Undercart=Undercart_DOWN ;
    return Undercart;
    }

    void turnGreen()
    {
    cout << "--------------------------绿灯,请通行------------------------" << endl;
    light = green;
    }

    void turnRed()
    {
    cout << "-----------------------红灯,禁止通行--------------------------" << endl;
    light = red;
    }

    int main()
    {
    while (1)
    {
    cout << "是否有车进入(1代表进入,其余代表没有):";
    cin >> carIn;
    if(carIn!=1)
    {
    cout<<"无车进入!等待中...";
    cout << "是否有车进入(1代表进入,其余代表没有):";
    cin >> carIn;
    }
    if (carIn == 1)
    {
    if (switchUndercartUp()) turnGreen();
    }

        while (light)
        {
            cout << "车是否离开:";
            cin >> carOut;
    		if(carOut!=1)
    	{
    		cout<<"车还未离开!等待中...";
    		cout << "车是否离开:";
    		cin >> carIn;
    	}
            if (carOut == 1)
            {
                if (!switchUndercartDOWN())         turnRed();
            }
    	
    	}
        
    }
    return 0;
    

    }

    运行结果:

  • 相关阅读:
    学习中的坑
    友链
    CF1131E String Multiplication 题解
    CF438E The Child and Binary Tree 题解
    [WC2005]友好的生物题解
    [IOI2016]shortcut 题解
    CF911F [Tree Destruction] 题解
    状压dp技巧之轮廓线 hdu1400/poj2411acwing291 蒙德里安的梦想
    TG-WC2021 笔记
    拯救世界2题解
  • 原文地址:https://www.cnblogs.com/New-Lee/p/6140575.html
Copyright © 2011-2022 走看看