福利
2025-05-30 15:00:41
发布于:浙江
活动仅限于链接描述
请把号码发至评论区。
#include <iostream>
#include <string>
#include <random>
#include <vector>
#include <algorithm>
std::string generateLotteryNumber() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 9);
std::vector<int> redBalls;
while (redBalls.size() < 3) {
int num = dis(gen);
if (std::find(redBalls.begin(), redBalls.end(), num) == redBalls.end()) {
redBalls.push_back(num);
}
}
int blueBall = dis(gen);
std::string redPart;
for (int num : redBalls) {
redPart += std::to_string(num);
}
std::string bluePart = std::to_string(blueBall);
return redPart + bluePart;
}
int main() {
std::string lotteryNumber = generateLotteryNumber();
std::cout << "生成的双色球号码是:" << lotteryNumber << std::endl;
std::cout << "(前3位为红球,最后1位为蓝球)" << std::endl;
return 0;
}
这里空空如也
有帮助,赞一个