跳到正文

Kobelhz

2027696

借曼巴微光,渡人间漫长

在洛谷打开
资料、奖项与版本

资料

编号
2027696
抓取

GOOD GOOD STUDY,DAY DAY UP.

谁能打出来

C++
֍ ۞ ۩ ❂ ☬ ☸ ✡
♔ ♕ ♖ ♗ ♘ ♙
♚ ♛ ♜ ♝ ♞ ♟

https://m.smzdm.com/p/68826375/

c++

这些题是我编的

星际跃迁网络 (Interstellar Jump Network)

星际跃迁引擎 (Stellar Jump Engine)

彩球分配难题 (Colorful Ball Distribution)

Atcoder

猜数字游戏

C++
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <fstream>
#include <string>
#include <iomanip>
#include<windows.h>
using namespace std;
int globalHighScore = 0;
const string SCORE_FILE = "highscore.txt";
void loadHighScore();
void saveHighScore(int score);
void showRules();
void playGame();
void clearScreen();
void loadHighScore() {
    ifstream inFile(SCORE_FILE);
    if (inFile.is_open()) {
        inFile >> globalHighScore;
        inFile.close();
    } else {
        globalHighScore = 0;
    }
}
void saveHighScore(int score) {
    if (score > globalHighScore) {
        globalHighScore = score;
        ofstream outFile(SCORE_FILE);
        if (outFile.is_open()) {
            outFile << globalHighScore;
            outFile.close();
        }
    }
}
void clearScreen() {
#ifdef _WIN32
    system("cls");
#else
    system("clear");
#endif
}
void showRules() {
    clearScreen();
    cout << "========================================" << endl;
    cout << "       欢迎来到猜数字挑战!         " << endl;
    cout << "========================================" << endl;
    cout << endl;
    cout << "【游戏规则】" << endl;
    cout << "1. 系统会在指定范围内随机生成一个整数。" << endl;
    cout << "2. 你需要在有限的次数内猜出这个数字。" << endl;
    cout << "3. 每次猜测后,系统会提示'太大'或'太小'。" << endl;
    cout << "4. 剩余次数越多,最终得分越高!" << endl;
    cout << "5. 输入非数字字符将被视为无效输入。" << endl;
    cout << endl;
    cout << "【难度等级】" << endl;
    cout << "1. 简单: 1-50,   8次机会" << endl;
    cout << "2. 中等: 1-100,  7次机会" << endl;
    cout << "3. 困难: 1-500,  9次机会" << endl;
    cout << "========================================" << endl;
    cout << "按回车键返回主菜单...";
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    cin.get();
}
void playGame() {
    int difficulty;
    int maxRange;
    int maxAttempts;
    while (true) {
        cout << "\n请选择难度 (1-简单, 2-中等, 3-困难, 0-返回): ";
        if (!(cin >> difficulty)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "无效输入,请输入数字。" << endl;
            continue;
        }
        if (difficulty == 0) return;
        switch (difficulty) {
            case 1:
                maxRange = 50;
                maxAttempts = 8;
                break;
            case 2:
                maxRange = 100;
                maxAttempts = 7;
                break;
            case 3:
                maxRange = 500;
                maxAttempts = 9;
                break;
            default:
                cout << "无效的难度选择,请重试。" << endl;
                continue;
        }
        break;
    }
    srand(static_cast<unsigned int>(time(0)));
    int targetNumber = rand() % maxRange + 1;
    int guess;
    int attemptsLeft = maxAttempts;
    bool won = false;
    clearScreen();
    cout << "========================================" << endl;
    cout << "      游戏开始! 范围: 1-" << maxRange << endl;
    cout << "      你共有 " << maxAttempts << " 次机会" << endl;
    cout << "========================================" << endl;
    while (attemptsLeft > 0) {
        cout << "\n剩余机会: " << attemptsLeft << endl;
        cout << "请输入你的猜测: ";
        if (!(cin >> guess)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << " 请输入有效的整数!" << endl;
            continue;
        }
        if (guess < 1 || guess > maxRange) {
            cout << " 数字超出范围 (1-" << maxRange << ")!" << endl;
            continue;
        }
        attemptsLeft--;
        if (guess == targetNumber) {
            won = true;
            break;
        } else if (guess < targetNumber) {
            cout << " 太小了! 再大一点。" << endl;
        } else {
            cout << " 太大了! 再小一点。" << endl;
        }
    }
    int score = 0;
    if (won) {
        score = 100 + (attemptsLeft * 10);
        cout << "\n 恭喜你! 猜对了! 数字就是 " << targetNumber << endl;
        cout << " 本局得分: " << score << endl;
        saveHighScore(score);
    } else {
        cout << "\n 游戏结束! 机会用完了。" << endl;
        cout << " 正确答案是: " << targetNumber << endl;
        cout << " 本局得分: 0" << endl;
    }
    cout << "\n当前最高分: " << globalHighScore << endl;
    cout << "按回车键继续...";
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    cin.get();
}
int main() {
    loadHighScore();
    int choice;

    while (true) {
        clearScreen();
        cout << "========================================" << endl;
        cout << "       猜数字大挑战                 " << endl;
        cout << "========================================" << endl;
        cout << "1. 开始游戏" << endl;
        cout << "2. 查看规则" << endl;
        cout << "3. 退出游戏" << endl;
        cout << "----------------------------------------" << endl;
        cout << "当前最高分: " << globalHighScore << endl;
        cout << "========================================" << endl;
        cout << "请选择 (1-3): ";
        if (!(cin >> choice)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            continue;
        }
        switch (choice) {
            case 1:
                playGame();
                break;
            case 2:
                showRules();
                break;
            case 3:
                cout << "感谢游玩,再见!" << endl;
                return 0;
            default:
                cout << "无效选择,请重试。" << endl;
                Sleep(600); // 稍微暂停让用户看到提示
                break;
        }
    }
    return 0;
}

有趣的小游戏(开车)

小游戏

mc我的世界

https://www.luogu.com.cn/user/1684892

还没有收录这位用户的文章。