啊?
2024-06-08 16:42:13
发布于:浙江
68阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
bool isValid(const std::vector<int>& digits, int n) {
std::vector<int> a(digits);
std::sort(a.begin(), a.end());
int sum = 0;
for (int i = 0; i < 5; ++i) {
sum = sum * 10 + a[i];
}
return sum % n == 0;
}
void printAnswer(int n) {
for (int b1 = 0; b1 < 10; ++b1) {
for (int b2 = b1 + 1; b2 < 10; ++b2) {
for (int b3 = b2 + 1; b3 < 10; ++b3) {
for (int b4 = b3 + 1; b4 < 10; ++b4) {
for (int b5 = b4 + 1; b5 < 10; ++b5) {
std::vector<int> b = {b1, b2, b3, b4, b5};
std::sort(b.begin(), b.end());
int a = n * (b[0] * 10000 + b[1] * 1000 + b[2] * 100 + b[3] * 10 + b[4]);
std::vector<int> aDigits = {a / 10000, a / 1000 % 10, a / 100 % 10, a / 10 % 10, a % 10};
if (isValid(aDigits, n)) {
std::cout << std::string(aDigits.begin(), aDigits.end()) << " / "
<< std::string(b.begin(), b.end()) << std::endl;
}
}
}
}
}
}
}
int main() {
int n;
std::cin >> n;
if (n >= 2 && n <= 79) {
printAnswer(n);
} else {
std::cout << "No answer." << std::endl;
}
return 0;
}
全部评论 1
湖北不后悔
2024-06-22 来自 北京
0
有帮助,赞一个