#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long num[9]={1,2,3,4,5,6,7,8,9};
long long theMax = 0;
bool isok(long long sum) {
if(sum / 1000000000 == 0 && sum / 100000000 != 0) {
int vis[20];
memset(vis,0,20);
while(sum != 0) {
int x = sum % 10;
sum /= 10;
if(x == 0 || vis[x] == 1) return false;
else vis[x] = 1;
}
return true;
} else return false;
}
bool solve(long long pos) { //乘号的位置
long long c1 = 1, sum1 = 0;
for(long long i=pos; i>=0; i--) {
sum1 += num[i] * c1;
c1 *= 10;
}
long long c2 = 1, sum2 = 0;
for(long long i=8; i>pos; i--) {
sum2 += num[i] * c2;
c2 *= 10;
}
long long temp = sum1 * sum2;
if(temp > theMax && isok(temp)) theMax = temp;
}
void print() {
for(int i=0; i<9; i++) {
printf("%d ",num[i]);
}
printf("\n");
}
int main() {
for(long long i=0; i<4; i++) {
do{
solve(i);
}while(next_permutation(num,num+9));
}
printf("%d\n",theMax);
return 0;
}
//821935476
18蓝桥国赛JavaB第二题(全排列)
最新推荐文章于 2020-06-07 15:46:26 发布