学习内容:
C#
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
bool bo(int i ,int j);
int main(){
int max = 0;
for(int i = 100 ; i < 1000;i++){
for(int j = 100 ; j < 1000;j++){
if(bo(i,j) && max < (i*j))
max = i*j;
}
}
printf("%d\n",max);
return 0;
}
bool bo(int i ,int j){
int num = i * j;
char arr[1000] = {'\0'};
char arr1[1000] = {'\0'};
sprintf(arr,"%d",num);
int n = strlen(arr);
int a = 0;
for(int i = n-1;i>=0;i--){
arr1[a++] = arr[i];
}
if(!strcmp(arr,arr1))
return true;
else
return false;
}
JAVA
package exercise;
public class _最大回文乘积 {
public static boolean call(int n) {
int tep = n, x = 0;
while (tep != 0) {
x = 10 * x + tep % 10;
tep /= 10;
}
if (x == n) {
return true;
}else {
return false;
}
}
public static void main(String[] args) {
int max = 0;
for (int i = 100; i < 1000; i++) {
for (int j = 100; j < 1000; j++) {
if(call(i * j)&&(i*j)>max) {
max = i*j;
}
}
}
System.out.println(max);
}
}