键盘输入5个1-9之间的数字, 在屏幕上输出由这5个数字构成的一个精确成立的除法等式
2、从键盘输入5个1-9之间的数字, 在屏幕上输出由这5个数字构成的一个精确成立的除法等式(只须输出一个解),或显示No表示无解。例如,输入1、2、1、2、2,一个正确的输出可以是22/2=11。
程序代码:#include <iostream>
#include <algorithm>
int main() {
using namespace std;
int test[5], flag = 1;
for(int i = 0; i < 5; i++)
cin >> test[i];
do {
if((test[0] * 10 + test[1]) / test[2] == (test[3] * 10 + test[4]) &&
(test[0] * 10 + test[1]) % test[2] == 0) {
cout << test[0] << test[1] << " / " << test[2] << " = " << test[3] << test[4] << endl;
break;
} else if((test[0] * 10 + test[1]) / (test[2] * 10 + test[3]) == test[4] &&
(test[0] * 10 + test[1]) % (test[2] * 10 + test[3]) == 0) {
cout << test[0] << test[1] << " / " << test[2] << test[3] << " = " << test[4] << endl;
break;
}
} while(flag = next_permutation(test, test + 5));
if(!flag)
cout << "Not found!" << endl;
return 0;
}
