Tools.h

· · 个人记录

// Copyright (C) since 2026 _auto_ / hwz007
// All rights reserved

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

mt19937 mrand(time(0));

class IORedirector{
private:
    streambuf* old_cin_buf;
    streambuf* old_cout_buf;
    ifstream input_file;
    ofstream output_file;
    bool input_redirected;
    bool output_redirected;

public:
    explicit IORedirector(const string& in_file = "", const string& out_file = "")
        : old_cin_buf(nullptr), old_cout_buf(nullptr),
          input_redirected(false), output_redirected(false){

        if(!in_file.empty()){
            input_file.open(in_file);
            if(input_file.is_open()){
                old_cin_buf = cin.rdbuf(input_file.rdbuf());
                input_redirected = true;
            }else{
                system("cls");
                cout << "错误 : 找不到指定文件 " << in_file << "\n";
                exit(0);
            }
        }
        if(!out_file.empty()){
            output_file.open(out_file);
            if(output_file.is_open()){
                old_cout_buf = cout.rdbuf(output_file.rdbuf());
                output_redirected = true;
            }
        }
    }

    ~IORedirector(){
        if(input_redirected && old_cin_buf){
            cin.rdbuf(old_cin_buf);
            if(output_redirected && old_cout_buf){
                cout.rdbuf(old_cout_buf);
            }
        }
        if(output_redirected && old_cout_buf){
            cout.rdbuf(old_cout_buf);
        }
    }
    IORedirector(const IORedirector&) = delete;
    IORedirector& operator=(const IORedirector&) = delete;

    IORedirector(IORedirector&& other) noexcept
        : old_cin_buf(other.old_cin_buf),
          old_cout_buf(other.old_cout_buf),
          input_redirected(other.input_redirected),
          output_redirected(other.output_redirected){
        other.old_cin_buf = nullptr;
        other.old_cout_buf = nullptr;
        other.input_redirected = false;
        other.output_redirected = false;
    }
};

namespace Color{
    const string reset   = "\033[0m";
    const string red     = "\033[31m";
    const string green   = "\033[32m";
    const string yellow  = "\033[33m";
    const string blue    = "\033[34m";
    const string magenta = "\033[35m";
    const string cyan    = "\033[36m";
    const string white   = "\033[37m";
    const string bold    = "\033[1m";
}

const string SAVE = "Copyright (C) since 2026 _auto_ / hwz007\nAll rights reserved\n\n";

const string NOW_V = "V 0.4.1\n\n";

const vector<string> UPDATE_DAILY = {
    "V 0.1.1 更新内容 : \n    1. 优化了 \"集训\" 界面显示\n    2. 移除了彩蛋,并修复了无限刷钱的 Bug\n\n",
    "V 0.1.2 更新内容 : \n    1. 更好的操作系统\n\n",
    "V 0.1.3 更新内容 : \n    1. 优化代码架构,提升运行速度\n\n",
    "V 0.1.4 更新内容 : \n    1. 现在,打开调试工具需要管理员权限\n\n",
    "V 0.2.0 更新内容 : \n    1. 主界面会随机显示批话(摘自洛谷用户 dAniel_lele )\n\n",
    "V 0.3.0 更新内容 : \n    1. 新增存档功能,游戏内每周自动存档\n    2. 修复若干 Bug\n\n",
    "V 0.3.1 更新内容 : \n    1. 比赛功能开启内测\n\n",
    "V 0.3.2 更新内容 : \n    1. 优化比赛系统\n\n",
    "V 0.3.3 更新内容 : \n    1. 优化比赛系统\n    2. 调整代码架构,隐藏调试工具\n    3. 修复若干 Bug\n\n",
    "V 0.4.0 更新内容 : \n    1. 完善比赛系统,添加游戏胜利目标\n    2. 修复若干 Bug\n\n",
    "V 0.4.1 更新内容 : \n    1. 天赋功能开启内测\n\n"
};

const string PASSWORD = "PenaltyKingAKIOI";

const vector<string> BULLSHIT = {
    "\"当你在幻想上天会给你开一扇窗的时候,你已经输一半了\"",
    "\"不要害怕跟比自己强的人对线。当他已经无理到用自己的强弱来对线时,这个人已经无药可救了\"",
    "\"永远拿着早就不属于自己的能力在欺骗\"",
    "\"由俭入奢易,由奢入俭难。谁不曾幻想多当一会儿赢家呢,只是幻想永远是幻想罢了\"",
    "\"脑子不好是硬伤\"",
    "\"如果平时训练的时候没有压力每天摆烂从不从自己身上找原因,正式考完需要承担原本可以分摊到每天的压力\"",
    "\"有些事情,你没有必要对它有责任感,毕竟没有人对它有责任感\"",
    "\"戒一周游戏都戒不明白吗?\"",
    "\"让每一个时刻的你,不要成为另一个时刻的累赘。仅此而已\"",
    "\"活在这里…好累…如果上天不愿意让我活在一具能赢的躯体,能不能至少让我活在一具输了也不会难受的…\"",
    "\"因为别人比自己强而讨厌他/她是正常的吗…\"",
    "\"不要去思考未来,把这留给未来的你\"",
    "\"该认真一点了,他们已经超越你了,为什么还不端正态度?以前的你会因为这个天天夜夜破防,现在的你为何别得这般无耻?\"",
    "\"享受胜利就像吸毒,没有意义,容易上瘾,使人麻痹,无法持续\"",
    "\"为了守住友谊而看淡竞争,而不是为了看淡竞争而守住友谊\"",
    "\"你不能只在别人比你菜的时候才把别人当成朋友\"",
    "\"你羡慕啥呢?别人不过是学术比你强,脑子比你牛,天赋比你高,学习比你卷,干事效率比你高,进步比你快,性格比你好,人际关系比你好,情感比你赢,前途比你广,看不起你罢了,有什么好羡慕的呢?对吧?\"",
    "\"你不能只在你输的时候才想到要努力\"",
    "\"活着是干啥的是应该放在如何活着之前思考的吗?还是说都是毫不值得思考的问题\"",
    "\"把世界幻想得太简单,把自己幻想得太幸运\"",
    "\"日常做题过一个题理应与打比赛过一个题获得相同的成就感。别再执着于面子\"",
    "\"有过过去不代表会有未来\"",
    "\"又有谁会记住自己无心立下的承诺\"",
    "\"积极乐观,不意味着也不应基于忘却乃至回避那段不堪而屈辱的过去\"",
    "\"自信不应当靠虚伪成就\"",
    "\"不要为功利的一丝希望而活,你的人生不止有它,它也不配占据你活着的全部理由\"",
    "\"当你没能达到目标的时候,反思一下你定目标的能力\"",
    "\"渴望改变别人观点使别人认同自己是一件极度愚蠢且自负的行为\"",
    "\"运气在信息学竞赛中没有用,请不要为你水平菜找借口说运气不好\""
};

const vector<string> SKILL = {"Ad-hoc大师", "一飞冲天", "急速学习", "慢热型选手"};