lg/CF 跳题器

· · 个人记录

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>

using namespace std; 

int last_move_time = clock();
void TopWindow() {
    HWND hWnd = GetConsoleWindow();
    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
void NoTopWindow() {
    HWND hWnd = GetConsoleWindow();
    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
void setpos(int x, int y) {
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void COLOR_PRINT(const char *s, int x) {
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE) ;
    SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | x);
    printf(s);
    SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
void HideCursor() {
    CONSOLE_CURSOR_INFO cursor_info = {1, 0}; // ??????,???1,????
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); // ?????????
}
bool IsConsoleWindowInForeground() {
    HWND consoleWindow = GetConsoleWindow();
    HWND foregroundWindow = GetForegroundWindow();
    return consoleWindow == foregroundWindow;
}

int pos = 1;
void rand_problem() {
    system("cls");
    while(1) {
        TopWindow();
        setpos(0, 0); 
        if(pos != 1) {
            cout << "1.CF";
        }
        else {
            string s = "1.CF";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 2) {
            cout << "2.lg";
        }
        else {
            string s = "2.lg";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 3) {
            cout << "3.exit";
        }
        else {
            string s = "3.exit";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(last_move_time > clock() || !IsConsoleWindowInForeground() && pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_TAB) & 0x8000) {
            pos = (pos == 0 ? 1 : 0);
            last_move_time = clock() + 100;
        }
        if(pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_RETURN) & 0x8000) {
            last_move_time = clock() + 100;
            if(pos == 1) {             
                string s = "start https://codeforces.com/problemset/problem/";
                s += char('0' + rand() % 3 + 1);
                s += char('0' + rand() % 10);
                s += char('0' + rand() % 10);
                s += char('0' + rand() % 10);
                s += "/";
                s += char('A' + rand() % 5);
                system(s.c_str());
                system("cls"); 
            }
            else if(pos == 2) {
                string s = "start https://www.luogu.com.cn/problem/";
                int kind = rand() % 3;
                s += ((kind == 0 ? "P" : (kind == 1 ? "B" : "CF")));
                s += char('0' + rand() % (kind == 1 || kind == 2 ? 1 : 9) + 1 + (kind == 1));
                s += char('0' + rand() % 10);
                s += char('0' + rand() % 10);
                s += char('0' + rand() % 10);
                if(kind == 2) {
                    s += char('A' + rand() % 5);
                } 
                system(s.c_str());
                system("cls"); 
            }
            else if(pos == 3) {
                return;
            }
        }
        if(GetAsyncKeyState(VK_DOWN) & 0x8000) {
            pos = min(pos + 1, 3);
            last_move_time = clock() + 100; 
        }
        if(GetAsyncKeyState(VK_UP) & 0x8000) {
            pos = max(pos - 1, 1);
            last_move_time = clock() + 100;
        }
    }
}
void choose_problem() {
    system("cls");
    pos = 1;
    while(1) {
        TopWindow();
        setpos(0, 0); 
        if(pos != 1) {
            cout << "1.CF";
        }
        else {
            string s = "1.CF";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 2) {
            cout << "2.lg";
        }
        else {
            string s = "2.lg";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 3) {
            cout << "3.exit";
        }
        else {
            string s = "3.exit";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(last_move_time > clock() || !IsConsoleWindowInForeground() && pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_TAB) & 0x8000) {
            pos = (pos == 0 ? 1 : 0);
            last_move_time = clock() + 100;
        }
        if(pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_RETURN) & 0x8000) {
            last_move_time = clock() + 100;
            if(pos == 1) {
                string s = "start https://codeforces.com/problemset/problem/CF";
                string now;
                cout << "enter id(like number 114):";
                cin >> now;
                s += now;
                s += "/";
                cout << "enter letter(like letter \'A\'):";
                cin >> now;
                s += now;
                system(s.c_str());
                system("cls");
            }
            else if(pos == 2) {
                string s = "start https://www.luogu.com.cn/problem/P";
                string now;
                cout << "enter id(like 1145):";
                cin >> now;
                s += now;
                system(s.c_str());
                system("cls");
            }
            else if(pos == 3) {
                return;
            }
        }
        if(GetAsyncKeyState(VK_DOWN) & 0x8000) {
            pos = min(pos + 1, 3);
            last_move_time = clock() + 100; 
        }
        if(GetAsyncKeyState(VK_UP) & 0x8000) {
            pos = max(pos - 1, 1);
            last_move_time = clock() + 100;
        }
    }
}

int main() {
    HideCursor(); 
    TopWindow();
    srand(time(0));
    a :
    cout << "press the key tab to hide the cursur, and then, it's will not still run when you don't want to run it, if you need it, you can press key tab again.\n";
    system("pause");
    system("mode con cols=30 lines=20");
    system("color 02");
    while(1) {
        TopWindow();
        setpos(0, 0);
        if(pos != 1) {
            cout << "1.rand";
        }
        else {
            string s = "1.rand";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 2) {
            cout << "2.choose";
        }
        else {
            string s = "2.choose";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(pos != 3) {
            cout << "3.exit";
        }
        else {
            string s = "3.exit";
            COLOR_PRINT(s.c_str(), 32);
        }
        cout << "\n";
        if(last_move_time > clock() || !IsConsoleWindowInForeground() && pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_TAB) & 0x8000) {
            pos = (pos == 0 ? 1 : 0);
            last_move_time = clock() + 100;
        }
        if(pos == 0) {
            continue;
        }
        if(GetAsyncKeyState(VK_RETURN) & 0x8000) {
            last_move_time = clock() + 300;
            if(pos == 1) {                    
                rand_problem();
            }
            else if(pos == 2) {
                choose_problem();
            }
            else if(pos == 3) {
                return 0;
            }
        }
        if(GetAsyncKeyState(VK_DOWN) & 0x8000) {
            pos = min(pos + 1, 3);   
            last_move_time = clock() + 100; 
        }
        if(GetAsyncKeyState(VK_UP) & 0x8000) {
            pos = max(pos - 1, 1);
            last_move_time = clock() + 100;
        }
    }
    return 0;
}