palsquare.c
# include <stdio.h>
char num[21]="0123456789ABCDEFGHIJ";
int N;
char n[21];
jinzhi(int i)
{
memset(n,'\0',sizeof(n));
int j=0;
char t;
int x=0,y;
while(i>=N)
{
n[j]=num[i%N];
i/=N;
j++;
}
if (i==0)
n[j]='\0';
else
n[j]=num[i],n[j+1]='\0';
y=strlen(n)-1;
while (x<=y)
{
t=n[x];
n[x]=n[y];
n[y]=t;
x++;
y--;
}
}
int palindromic()
{
int i=0,j;
j=strlen(n)-1;
while (i<=j)
{
if (n[i]!=n[j]) return (0);
i++;
j--;
}
return (1);
}
main ()
{
FILE *in=fopen ("palsquare.in","r");
FILE *out=fopen("palsquare.out","w");
int i;
fscanf (in,"%d",&N);
for (i=1;i<=300;i++)
{
jinzhi(i*i);
if (palindromic()!=0)
{
jinzhi(i);
fprintf (out,"%s ",n);
jinzhi(i*i);
fprintf (out,"%s\n",n);
}
}
fclose(in);
fclose(out);
exit(0);
}
posted @
2009-08-01 18:31
锦燕云
阅读(
130)
评论()
编辑
收藏
举报