本文共 1269 字,大约阅读时间需要 4 分钟。
题目链接>>>>>>
题目大意:
#include #include #include #include #include #include #include #include using namespace std;int main(){ int n, a[10], first = 1; while (scanf("%d", &n) != EOF,n) { if (first) { first = 0; } else { printf("\n"); } //以上是两组数据之间输出空行的技巧 int num1 = 1, num2 = 1; int side = 98765 / n; //这里稍微降低了一下复杂度 int flag1 = 0; for (num1 = 1234; num1 <= side; num1++) { int flag = 1; num2 = num1 * n; a[0] = num2 / 10000; a[1] = num2 / 1000 % 10; a[2] = num2 / 100 % 10; a[3] = num2 / 10 % 10; a[4] = num2 % 10; a[5] = num1 / 10000; a[6] = num1 / 1000 % 10; a[7] = num1 / 100 % 10; a[8] = num1 / 10 % 10; a[9] = num1 % 10; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j != i && a[i] == a[j]) { //这里判断10位数是否有重复的方法 flag = 0; } } } if (flag) { for (int i = 0; i < 5; i++)cout << a[i]; cout << " / "; //注意这里"/"和"="左右两边都有空格 for (int i = 5; i < 10; i++)cout << a[i]; cout << " = " << n << endl; flag1 = 1; } } if (flag1 == 0) { printf("There are no solutions for %d.\n", n); } } return 0;}
2018-04-08
转载于:https://www.cnblogs.com/00isok/p/8748754.html