- 长方形面积计算
抽奖游戏
- 2025-6-26 16:25:09 @
#include<iostream>
#include<cstdlib>
#include<ctime>
#include <windows.h>
using namespace std;
void functionWithoutArgs(){
system("color 9f");
char v;
int l, n = 6; // 初始化剩余抽奖次数为6
cout<<"欢迎来玩抽奖游戏!!!"<<endl;
// 只在游戏开始时显示一次提示信息
cout<<"有奖有罚!"<<endl;
// 使用循环控制抽奖次数
while(n > 0){
cout<<"还可抽"<< n <<"次"<<endl ;
cout<<"请输入抽奖次数和任意字符开始游戏(抽奖次数建议为12-372之间)"<<endl;
// 验证输入的抽奖次数是否为有效整数
bool validInput = false;
while(!validInput) {
while(!(cin >> l)) {
cout << "错误:请输入有效的整数作为抽奖次数!" << endl;
cin.clear();
cin.ignore(10000, '\n');
}
// 新增:检查抽奖次数是否在有效范围内
if (l < 12 || l > 372) {
cout << "警告:抽奖次数建议为12-372之间。继续可能导致显示异常,是否继续?(Y/N)" << endl;
char confirm;
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
validInput = true;
} else {
// 重置输入流,重新获取输入
cin.clear();
cin.ignore(10000, '\n');
cout << "请重新输入抽奖次数:" << endl;
}
} else {
validInput = true;
}
}
// 读取并丢弃用户输入的任意字符(原代码中读取后又重置为'a',这没有意义)
cin >> v;
cout << "抽奖动画开始:" << endl;
// 重置v为'a'开始动画效果
v = 'a';
for(int i = 1; i <= l; ++i){
++v;
cout << v << " ";
if(v == 'z'){
v = 'a';
}
Sleep(0.8); // 使用Windows API的Sleep函数
}
cout << endl;
// 奖项判定
cout << "=== 抽奖结果 ===" << endl;
// 只在程序开始时初始化一次随机数种子
static bool seedInitialized = false;
if (!seedInitialized) {
srand(static_cast<unsigned int>(time(0)));
seedInitialized = true;
}
int randomNum = rand() % 100;
// 奖项判定逻辑(保持原概率分布)
if(randomNum < 1) { // 1%
cout << "恭喜您获得传说级大奖!!!" << endl;
cout << "奖品:私人太空旅行体验券!" << endl;
} else if(randomNum < 2) { // 1%
cout << "恭喜您获得传说级大奖!!!" << endl;
cout << "奖品:豪华游艇一周使用权!" << endl;
} else if(randomNum < 3) { // 1%
cout << "恭喜您获得传说级大奖!!!" << endl;
cout << "奖品:私人岛屿度假套餐!" << endl;
} else if(randomNum < 5) { // 2%
cout << "恭喜您获得特等奖!!!" << endl;
cout << "奖品:豪华环球旅行套餐!" << endl;
} else if(randomNum < 7) { // 2%
cout << "恭喜您获得超稀有奖!!" << endl;
cout << "奖品:定制黄金雕像!" << endl;
} else if(randomNum < 9) { // 2%
cout << "恭喜您获得超稀有奖!!" << endl;
cout << "奖品:专业摄影器材套装!" << endl;
} else if(randomNum < 11) { // 2%
cout << "恭喜您获得超稀有奖!!" << endl;
cout << "奖品:高端音响系统!" << endl;
} else if(randomNum < 13) { // 2%
cout << "恭喜您获得超稀有奖!!" << endl;
cout << "奖品:豪华手表收藏!" << endl;
} else if(randomNum < 16) { // 3%
cout << "恭喜您获得一等奖!!" << endl;
cout << "奖品:最新款旗舰笔记本电脑!" << endl;
} else if(randomNum < 19) { // 3%
cout << "恭喜您获得一等奖!!" << endl;
cout << "奖品:高端游戏主机一台!" << endl;
} else if(randomNum < 22) { // 3%
cout << "恭喜您获得一等奖!!" << endl;
cout << "奖品:最新款智能手机一部!" << endl;
} else if(randomNum < 25) { // 3%
cout << "恭喜您获得二等奖!" << endl;
cout << "奖品:高端机械键盘套装!" << endl;
} else if(randomNum < 28) { // 3%
cout << "恭喜您获得二等奖!" << endl;
cout << "奖品:专业无线鼠标!" << endl;
} else if(randomNum < 31) { // 3%
cout << "恭喜您获得二等奖!" << endl;
cout << "奖品:精美手表一块!" << endl;
} else if(randomNum < 34) { // 3%
cout << "恭喜您获得二等奖!" << endl;
cout << "奖品:智能家居套装!" << endl;
} else if(randomNum < 37) { // 3%
cout << "恭喜您获得三等奖!" << endl;
cout << "奖品:无线降噪耳机一副!" << endl;
} else if(randomNum < 40) { // 3%
cout << "恭喜您获得三等奖!" << endl;
cout << "奖品:智能手环一个!" << endl;
} else if(randomNum < 43) { // 3%
cout << "恭喜您获得三等奖!" << endl;
cout << "奖品:运动背包一个!" << endl;
} else if(randomNum < 46) { // 3%
cout << "恭喜您获得三等奖!" << endl;
cout << "奖品:蓝牙音箱一个!" << endl;
} else if(randomNum < 49) { // 3%
cout << "您获得了幸运奖!" << endl;
cout << "奖品:100元购书券!" << endl;
} else if(randomNum < 52) { // 3%
cout << "您获得了幸运奖!" << endl;
cout << "奖品:精美礼品卡一张!" << endl;
} else if(randomNum < 55) { // 3%
cout << "您获得了幸运奖!" << endl;
cout << "奖品:品牌充电宝一个!" << endl;
} else if(randomNum < 58) { // 3%
cout << "您获得了幸运奖!" << endl;
cout << "奖品:定制文具套装!" << endl;
} else if(randomNum < 61) { // 3%
cout << "您获得了幸运奖!" << endl;
cout << "奖品:精美书籍一套!" << endl;
} else if(randomNum < 64) { // 3%
cout << "您获得了普通奖..." << endl;
cout << "奖品:纪念徽章一枚。" << endl;
} else if(randomNum < 67) { // 3%
cout << "您获得了普通奖..." << endl;
cout << "奖品:精美书签一套。" << endl;
} else if(randomNum < 70) { // 3%
cout << "您获得了普通奖..." << endl;
cout << "奖品:定制明信片!" << endl;
} else if(randomNum < 73) { // 3%
cout << "手气一般般..." << endl;
cout << "惩罚:帮朋友做一件小事!" << endl;
} else if(randomNum < 76) { // 3%
cout << "手气一般般..." << endl;
cout << "惩罚:打扫卫生一次!" << endl;
} else if(randomNum < 79) { // 3%
cout << "手气一般般..." << endl;
cout << "惩罚:整理房间一小时!" << endl;
} else if(randomNum < 82) { // 3%
cout << "运气不太好哦..." << endl;
cout << "惩罚:做十道数学题!" << endl;
} else if(randomNum < 85) { // 3%
cout << "运气不太好哦..." << endl;
cout << "惩罚:唱一首儿歌!" << endl;
} else if(randomNum < 88) { // 3%
cout << "运气不太好哦..." << endl;
cout << "惩罚:做20个深蹲!" << endl;
} else if(randomNum < 91) { // 3%
cout << "运气不太好哦..." << endl;
cout << "惩罚:写一篇短文!" << endl;
} else if(randomNum < 94) { // 3%
cout << "非常遗憾..." << endl;
cout << "惩罚:给朋友讲一个冷笑话!" << endl;
} else if(randomNum < 96) { // 2%
cout << "非常遗憾..." << endl;
cout << "惩罚:明天早起跑步!" << endl;
} else if(randomNum < 98) { // 2%
cout << "非常遗憾..." << endl;
cout << "惩罚:完成一项小挑战!" << endl;
} else { // 2%
cout << "超级倒霉!" << endl;
cout << "惩罚:连续三天早起!" << endl;
}
// 减少剩余抽奖次数
n--;
// 抽奖之间添加分隔线,提高可读性
if(n > 0) {
cout << "\n----------------------------------------\n";
}
}
cout << "\n抽奖次数已用完,感谢参与!" << endl;
}
int main(){
functionWithoutArgs();
return 0;
}
1 条评论
-
苏芷萱 @ 2025-7-12 16:02:26
@张柏然 牛B
- 1
信息
- ID
- 1202
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者