用C++编1到1000的同构数

来源:百度知道 编辑:UC知道 时间:2024/05/20 17:32:10

#include<iostream>
using namespace std;
void search(int n)
{
int step,j=0,i1;
for(int i=1;i<n;i++)
{
i1=i;
step=10;
while((i1/10)!=0)
{
step=step*10;
i1=i1/10;
}

if((i*i)%step==i)
{
cout<<i<<endl;
j++;
}
}
if(j==0)
cout<<"Cannot find the number"<<endl;
}
int main()
{
int n;
cout<<"Please input the edge of the number"<<endl;
cin>>n;
search(n);
return 0;
}
差不多就这样吧,如果还要着的精确点,把int改成long int吧。效果也不是很明显,还有就是将其改成字符窜,按尾部进行比较,这里我就不写了,这个程序对1000以内的还是可以判断的,没有问题。