zoukankan      html  css  js  c++  java
  • 欧拉计划第4题题解

    Largest palindrome product

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

    Find the largest palindrome made from the product of two 3-digit numbers.

    最大回文乘积

    回文数就是从前往后和从后往前读都一样的数。由两个2位数相乘得到的最大回文乘积是 9009 = 91 × 99。

    找出由两个3位数相乘得到的最大回文乘积。

    解题思路

    这道题目没有什么好的思路。想到的办法就是枚举所有的三位数,求它们的乘积,然后在所有的回文乘积里找最大值就是我们的答案。

    实现代码如下:

    #include <bits/stdc++.h>
    using namespace std;
    int ans;
    bool check(int a) {
        int x = a, b = 0;
        while (x) {
            b = b * 10 + x % 10;
            x /= 10;
        }
        return a == b;
    }
    int main() {
        for (int i = 100; i < 1000; i ++)
            for (int j = i; j < 1000; j ++)
                if (check(i*j))
                    ans = max(ans, i*j);
        cout << ans << endl;
        return 0;
    }
    

    答案是 (906609)

  • 相关阅读:
    /etc/fstab 文件解释
    CRLF和LF
    Git远程操作详解
    jsp错误处理
    jsp隐式对象
    关于循环队列要注意的
    JSP动作元素
    JSP指令
    jsp语法简介
    jsp声明周期
  • 原文地址:https://www.cnblogs.com/quanjun/p/12322649.html
Copyright © 2011-2022 走看看