base+ball=games

版权声明:个人整理,仅供参考,请勿转载,如有侵权,请联系[email protected] https://blog.csdn.net/mooe1011/article/details/88931368

每个字母为0~9,使得式子成立

写了烂代码,过了,期待以后的改进

//#include<bits/stdc++.h>
using namespace std;




int main() {
	//int b = 0, a = 0, s = 0, e = 0, l = 0, g = 0, m = 0;
	//freopen("input.txt", "r", stdin);
	/*
	共7个字母baselgm
	int base = 1000 * b + 100 * a + 10 * s + e;
	int ball = 1000 * b + 100 * a + 10 * l + l;
	int games = 10000 * g + 1000 * a + 100 * m + 10 * e + s;
	化简  2000b+11*l+9s=10000g+800a+100m+9e
	11*l+9s的十位和个位=9e的十位和个位
	11*l+9s的百位和800a+100m的百位相等
	800a+100m的千位与2000b一样
	2000b的万位和g一样
	*/
	for (int l=0; l <= 9; l++) {
		for (int s=0; s <= 9; s++) {
			for (int a = 0; a <= 9; a++) {
				for (int m = 0; m <= 9; m++) {					
					int left = 11 * l + 9 * s;
					int right2 = 800 * a + 100 * m;
					
					if (left / 100 == right2 / 100 % 10) {						
						for (int e = 0; e <= 9; e++) {
							int right = 9 * e;
							if (left % 10 == right % 10 && left / 10 % 10 == right / 10) {
								
								for (int b = 0; b <= 9; b++) {
									int left2 = 2000 * b;
									if (left2 / 1000 % 10 == right2 / 1000) {
										for (int g = 0; g <= 9; g++) {
											if (left2 / 10000 == g) {
												int base = 1000 * b + 100 * a + 10 * s + e;
												int ball = 1000 * b + 100 * a + 10 * l + l;
												int games = 10000 * g + 1000 * a +
                                                 100 * m + 10 * e + s;
												cout << base << " + " << ball << " = " <<
                                                  games << endl;
											}
										}
									}
								}
							}
						}
					}
				}


			}

		}
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/mooe1011/article/details/88931368
今日推荐