跳到正文

个人记录

班会代码

OIer_ACMer约 7 分钟
原文
文章信息与版本

文章信息

发布
2024年2月25日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 7 分钟

版本

  1. v1当前
C++
#include <iostream>
using namespace std;
#include <ctime>
#define red  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //红色
#define nop SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);   //原色
#define blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE);			//蓝色
#define green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);  //绿色
#define white 	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);  //白色
#define pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);//粉色
#define ching SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);  //青色
class Clock
{
    int h;
    int m;
    int s;

public:
    void set(int hour, int min, int sec); // set(int ,int ,int )
    void tick();
    void show();
    void run();
};
void Clock::set(int hour, int min, int sec)
{
    h = hour;
    m = min;
    s = sec;
}
void Clock::tick()
{
    time_t t = time(NULL); // 取得当前时间
    while (time(NULL) == t)
        ;
    if (--s < 0)
    {
        s = 59;
        if (--m < 0)
        {
            m = 59;
            --h < 0;
        }
    }
}
void Clock::show()
{
    cout << '\r';
    // if (s <= 5)
    // {
    //     red
    // }
    if (h < 10)
    {
        cout << 0;
    }
    cout << h << ':';
    if (m < 10)
    {
        cout << 0;
    }
    cout << m << ':';
    if (s <= 5)
    {
        cout << "\a";
    }
    if (s < 10)
    {
        cout << 0;
    }
    cout << s << flush;
}
void Clock::run()
{
    while (h != 0 || m != 0 || s != 0)
    {
        tick();
        show();
        clock_t sta = clock();
        int a;
        // if (clock() - sta >= 200)
        // {
        //     cout << "\r";
        //     continue;
        // }
        // else
        // {
        //     cin >> a;
        //     if (clock() - sta >= 200)
        //     {
        //         cout << "\r";
        //         continue;
        //     }
        //     if (a == 1)
        //     {
        //         cout << "You are right!" << endl;
        //     }
        //     return;
        // }
    }
    cout << endl;
    cout << "Time Out!" << endl;
    cout << '\a' << '\n';
}
int main()
{
    char k;
    bool b[5];
    b[1] = b[2] = b[3] = b[4] = 0;
    while (1)
    {
        cout << "Are You ready?\n";
        cin >> k;
        if (k == 'y')
        {
            break;
        }
        else
        {
            continue;
        }
    }
    Clock c;
    // cout << "请输入倒计时的时间:";
    // int h1, m1, s1;
    // cin >> h1 >> m1 >> s1;
    int h1, m1, s1;
    h1 = 0;  // 多少小时
    m1 = 0;  // 多少分钟
    s1 = 10; // 多少秒
    // green
    cout << "请问1 + 1等于__" << endl;
    // white
    c.set(h1, m1, s1);
    c.run();
    int a[5];
    cout << "答题卡:" << endl;
    cout << "选手1:";
    cin >> a[1];
    cout << "选手2:";
    cin >> a[2];
    cout << "选手3:";
    cin >> a[3];
    cout << "选手4:";
    cin >> a[4];
    cout << endl << endl;
    cout << "选手 ";
    for (int i = 1; i <= 4; i++)
    {
        if (a[i] == 1)
        {
            b[i] = 1;
            cout << i << ' ';
        }
    }
    cout << "答案正确" << endl;
    cout << "第一个答对的人:";
    int u;
    cin >> u;
    if (u >= 1 && u <= 2 && b[u])
    {
        cout << "左边一方加一分!";
    }
    else if (u >= 3 && u <= 4 && b[u])
    {
        cout << "右边一方加一分";
    }
    else
    {
        cout << "没有正确答案,游戏结束";
    }
    return 0;
}
原文