十个数字不同,实现加减乘。暴力枚举法
/*
2016.08.29
此程序功能是实现十个个位数字的组合不同形式形成加减乘法,可以灵活变动以适应不同的要求
*/
#include<iostream>
using namespace std;
int main(){
int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int i0 = 0; (i0 < 10) && (a[i0] != -1); i0++){
a[i0] = -1;
if (i0 == 1)
for (int i1 = 0; (i1 < 10) && (a[i1] != -1); i1++){
a[i1] = -1;
int i2 = i1 + i0;
if ((i2 < 10) && a[i2] != -1){
a[i2] = -1;
for (int i3 = 0; (a[i3] != -1) && (i3 < 10); i3++){
a[i3] = -1;
for (int i4 = 0; (i3 > i4) && (a[i4] != -1); i4++){
a[i4] = -1;
int i5 = i3 - i4;
if (a[i5] != -1){
a[i5] = -1;
for (int i6 = 0; (a[i6] != -1) && (i6 < 10); i6++){
a[i6] = -1;
for (int i7 = 0; (a[i7] != -1) && (i7 < 10); i7++){
a[i7] = -1;
int i89 = i6*i7;
int i8 = i89 / 10, i9 = i89 % 10;
if ((a[i8] != -1) && (i8 != i9) && (a[i9] != -1)){
a[i8] = a[i9] = -1;
cout << i0 << " + " << i1 << " = " << i2 << endl;
cout << i3 << " - " << i4 << " = " << i5 << endl;
cout << i6 << " * " << i7 << " = " << i8 << i9 << endl;
return 0;
}
a[i7] = i7;
while (a[i7 + 1] == -1)i7++;
}
a[i6] = i6;
while (a[i6 + 1] == -1)i6++;
}
a[i5] = i5;
}
a[i4] = i4;
while (a[i4 + 1] == -1)i4++;
}
a[i3] = i3;
while (a[i3 + 1] == -1)i3++;
}
a[i2] = i2;
}
a[i1] = i1;
while (a[i1 + 1] == -1)i1++;
}
a[i0] = i0;
while (a[i0 + 1] == -1)i0++;
}
cout << "not exist!!!" << endl;
return 0;
}
- Js中实现日期加减--字符串转换成数字进行运算
- js金额数字格式化实现代码(加减逗号处理)
- 大数字的加减乘法实现
- python实现输入数字的连续加减方法
- CNN:人工智能之神经网络算法进阶优化,六种不同优化算法实现手写数字识别逐步提高,应用案例自动驾驶之捕捉并识别周围车牌号—Jason niu
- flash中随机产生20-100之间10个不同的数字,然后不能重复地随机取出这十个数字
- 【C】写一个宏将一个数字的奇数位和偶数位交换。实现两个int(32位)整数m和n的二进制表达中,位(bit)不同的个数
- 实现数字加减
- js金额数字格式化实现代码(加减逗号处理)
- jQuery实现购物车数字加减效果
- jQuery实现数字加减效果汇总
- python实现输入数字的连续加减
- 单片机:按键(使用中断)控制数码管的数字加减(c语言实现)
- 编程:用java 语言实现,输入一个数,就相应地输出的几维数组!||用1、2、2、3、4、5这六个数字,用java写一个函数,打印出所有不同的排列,要求:"4"不能在第三位,"3"与"5"不能相连
- jQuery实现数字加减效果汇总
- java实现十个数字组成一个加法式
- 安卓点击加减号实现数字加减功能
- jQuery实现购物车数字加减效果
- 实现点击加减数字进行变化
- 设计一个算法,要求在20个数字中(0到19)随机选取十个数字,但是这十个数字不能重复(用C语言或者OC实现)