/*
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;
}
原文:http://www.cnblogs.com/1996313xjf/p/5819702.html