C++ 用c+求解工程euler#4+;
回文数字的两种解读方式相同。由两个两位数的乘积构成的最大回文是9009=91×99 查找由两个3位数字的乘积构成的最大回文 这是我的代码。它适用于2位数的问题,给出了9009作为答案,但不适用于3位数的部分C++ 用c+求解工程euler#4+;,c++,C++,回文数字的两种解读方式相同。由两个两位数的乘积构成的最大回文是9009=91×99 查找由两个3位数字的乘积构成的最大回文 这是我的代码。它适用于2位数的问题,给出了9009作为答案,但不适用于3位数的部分 #include <iostream> using namespace std ; bool ispallin(int n) { int reverse = 0, temp; temp = n; while (temp != 0) { reverse = revers
#include <iostream>
using namespace std ;
bool ispallin(int n)
{
int reverse = 0, temp;
temp = n;
while (temp != 0)
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if (n == reverse)
return true;
else
return false;
}
int main() {
int a[999*999]={0},i,j,no;//0 implies no. at i th position is pallindrome
for(i=100;i<1000;i++)
{
for(j=100;j<1000;j++)
{
if(a[i*j]==0)//no. is pallin
{
if(ispallin(i*j))
no=i*j;
else a[i*j]=1;//no. at this pos is not pallindrome
}
}
}
cout<<no;
return 0;
}
#包括
使用名称空间std;
布尔伊斯帕林(国际北)
{
int reverse=0,温度;
温度=n;
while(温度!=0)
{
反向=反向*10;
反向=反向+温度%10;
温度=温度/10;
}
如果(n==反向)
返回true;
其他的
返回false;
}
int main(){
int a[999*999]={0},i,j,no;//0表示no。第i个位置是pallindrome
对于(i=100;i您的代码非常好,我会为函数添加更多的注释或可能有意义的名称,但这是一个好代码,答案不是您想要的,因为您从未确保结果是最高的。
也许700*700会是回文,但701*600也会是回文,我想你的案例一旦“我”变大,就会覆盖结果,即使polindrom变大。你说“它不起作用”是什么意思?没有给我正确的答案