题解 | #自守数#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <iostream>
using namespace std;
int main()
{
int a;
while(cin>>a)
{
int c=0;
if(a==0)
{
c=0;
}
for(int i=1;i<=a;i++)
{
int b=0;
int d=i*i;
int e=i;
while(e)
{
if( e%10!=d%10)
{
b=0;
break;
}
else
{
d=d/10;
e=e/10;
b=1;
}
}
if(b==1)
{
c++;
}
}
cout<<c+1;
}
return(0);
}
using namespace std;
int main()
{
int a;
while(cin>>a)
{
int c=0;
if(a==0)
{
c=0;
}
for(int i=1;i<=a;i++)
{
int b=0;
int d=i*i;
int e=i;
while(e)
{
if( e%10!=d%10)
{
b=0;
break;
}
else
{
d=d/10;
e=e/10;
b=1;
}
}
if(b==1)
{
c++;
}
}
cout<<c+1;
}
return(0);
}