题目链接https://acm.bnu.edu.cn/v3/statments/jag2016.pdf
思路
把乘积转换成字符串,然后暴力求解
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
int a[1005];
char s[100000000];
char str[100000000];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int maxx=0;
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
int t=a[i]*a[j];
sprintf(s,"%d",t);
if(t>maxx){
int k;
int len=strlen(s);
for(k=0;k<len;k++){
if(s[k]+1!=s[k+1])
break;
}
if(k==len-1){
memcpy(str,s,sizeof(str));
maxx=t;
}
}
}
}
if(maxx>0)
printf("%s\n",str);
else if(maxx==0)
printf("-1\n");
return 0;
}