原题链接:蓝桥杯算法提高VIP-排列式
解题思路:
        就是这么暴力。
参考代码 ① :
#include<bits/stdc++.h>
using namespace std;
bool arr[10];
void Judge(int mul, int i2) {
	int i1 = mul / i2, pos = 0, index;
	if (mul > 9876) return;
	
	char mulc[5], i1c[5], i2c[5];
	sprintf(mulc, "%d", mul); sprintf(i1c, "%d", i1); sprintf(i2c, "%d", i2);
	while (mulc[pos]) {
		arr[mulc[pos++] - '0'] = true;
	} pos = 0;
	
	while (i1c[pos]) {
		index = i1c[pos++] - '0';
		if (arr[index]) return;
		arr[index] = true;
	} pos = 0; 
	
	while (i2c[pos]) {
		index = i2c[pos++] - '0';
		if (arr[index]) return;
		arr[index] = true;
	}
	
	for (int i = 1; i < 10; i++)
		if (!arr[i]) return;
	printf("%s = %s x %s\n", mulc, i2c, i1c);
}
int main() {
	for (int mul = 1; mul < 9283; mul++)
		for (int i = 1; i < 101; i++) {
			if (mul%i != 0) continue;
			Judge(mul, i); memset(arr, 0, 10);
		}
}参考代码 ② :
#include<iostream> /* > _ < */
int main() {
	char Ans[][20] = { "4396 = 28 x 157",
                       "5346 = 18 x 297",
                       "5346 = 27 x 198", 
                       "5796 = 12 x 483", 
                       "5796 = 42 x 138", 
                       "6952 = 4 x 1738",
                       "7254 = 39 x 186", 
                       "7632 = 48 x 159",
                       "7852 = 4 x 1963", "" };
                       
	int index = 0;
	while (Ans[index][0])
		puts(Ans[index++]);
}0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
 
发表评论 取消回复