usaco palsquare

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yalishiyanzhouyu888/article/details/50659613
#include<stdio.h>
#include<stdlib.h>
int c[30],b;
bool pd(int n){
	int i;
	for(i=1;i<=n;i++)
	  if(c[i]!=c[n-i+1])
	    return false;
    return true;
}
void jz(int n){
	int ch[30],i=1,j,m=n;
	while(m>0){
		ch[i]=m%b;
		m/=b;
		i++;
	}
	for(j=i-1;j>=1;j--)
	  if(ch[j]<=9)printf("%d",ch[j]);
	  else printf("%c",(char)(ch[j]+55));
}
void work(int n){
	int i=1,j,k,m=n*n;
	while(m>0){
		c[i]=m%b;
		m/=b;
		i++;
	}
	if(pd(i-1)){
		jz(n);
		printf(" ");
		jz(n*n);
		puts("");
	}
    return;
}
int main(){
	freopen("palsquare.in","r",stdin);
	freopen("palsquare.out","w",stdout);
	scanf("%d",&b);
	int i;
	for(i=1;i<=300;i++)
	  work(i);
	return 0;
}

阅读更多

没有更多推荐了,返回首页