跳到正文

休闲·娱乐

测测你的运势(c党++派)

peiyixuan约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年1月13日
收录
2026年8月13日
更新
2026年10月4日
篇幅
约 3 分钟
获赞
1

版本

  1. v1当前

洛谷测运势是挺好玩的。但是… 我们可以手搓一个测运势的代码呀!!! 废话不多说,上代码!

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;

int main() {
	system("title 测运势");
	system("color 2f");
	Sleep(500);
	cout<<"按任意键开始测运势...\n";
	_getch();
	system("cls");
    // 获取系统时间组件
    time_t t = time(0);
    tm* a = localtime(&t);
    int e = a->tm_mday;
    int f = a->tm_mon + 1;
    int g = a->tm_year + 1900;
    
    // 计算运势索引 (0-8)
    int h[3] = { e, f, g};
    int i = 0;
    for (int j = 0; j < 3; j++) {
        i = (i * 17 + h[j]) % 10;
    }
    
    // 10种运势描述
    char k[10][20] = {
        "大吉", "吉", "中吉", "小吉", 
        "中平", "小凶", "中凶", "凶", "大凶","你完了"
    };
    
    // 宜事项库 (8个选项)
    char l[8][20] = {
        "读书学习", "投资理财", "外出旅行", "签订合约",
        "结交贵人", "运动健身", "创意工作", "购置新物"
    };
    
    // 忌事项库 (8个选项)
    char m[8][20] = {
        "冲动决策", "熬夜通宵", "口舌之争", "大额消费",
        "冒险投资", "拖延事务", "过度饮食", "重要谈判"
    };
    
    // 选择两个不同的宜事
    int n = (e + f) % 8;
    int o = (e + g) % 8;
    while (o == n) o = (o + 1) % 8;
    
    // 选择两个不同的忌事
    int p = (f + g) % 8;
    int q = (e + f + g) % 8;
    while (q == p) q = (q + 1) % 8;
    cout << "今日运势: " << k[i] << endl;
    cout << "宜: " << l[n] << "\n    " << l[o] << endl;
    cout << "忌: " << m[p] << "\n    " << m[q] << endl;
    cout<<"按任意键关闭程序...\n";
	_getch();
    return 0;
}

结合了我的毕生所学 其实啥都没学 刚好1400个字符

原文