Home > Database > Mysql Tutorial > USACO 1.2.4 Palindromic Squares

USACO 1.2.4 Palindromic Squares

WBOY
Release: 2016-06-07 15:00:52
Original
965 people have browsed it

USACO 1.2.4 Palindromic Squares 为盲打1 !为颈椎1 ! 题意:……一点要注意,题目的意思是说1~300这些数字的平方转换成对应的进制时是回文数即可,但是!每行的第一个数字是用要求的进制来表示的!!!!!!!!一开始测试案例错了我还真没看懂。 细节代

USACO 1.2.4 Palindromic Squares

     为盲打+1 !为颈椎+1 !

     题意:……一点要注意,题目的意思是说1~300这些数字的平方转换成对应的进制时是回文数即可,但是!每行的第一个数字是用要求的进制来表示的!!!!!!!!一开始测试案例错了我还真没看懂。

     细节+代码:

 

    

/*   
ID: 15257142   
LANG: C   
TASK: palsquare
*/ 
#include<stdio.h>
#include<string.h>
#include<math.h>
int n;
int trans(int num,char b[20]){
	int k,g;
	k = -1;
	while(num>0){
		k++;
		g = num%n;
		if(g>9)
			b[k] = g-10+'A';
		else
			b[k] = g-0+'0';
		num = num/n;
	}
	b[k+1] = '\0';
	return k;
}
int transnum(int num,int n,char e[20]){
	int k;
	k = -1;
	while(num>0){
		k++;
		if(num%n>9)
			e[k] = num%n-10+'A';
		else
			e[k] = num%n+'0';
		num = num/n;
	}
	return k;
}
int main(){ //太长了,一开始题意明确的话就不会现在这样……
	freopen("palsquare.in","r",stdin);
	freopen("palsquare.out","w",stdout);
	int i,j,k,g,t,f;
	char c[20],d[20],b[20],e[20];
	scanf("%d",&n);
	for(i = 1;i=f;j--)
			d[g-j] = b[j];
		d[g-j] = '\0';
		if(strcmp(c,d)==0){
			k = transnum(i,n,e);
			for(j = k;j>=0;j--)
				printf("%c",e[j]);
			printf(" ");
			printf("%s\n",b);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
</math.h></string.h></stdio.h>
Copy after login


 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template