palsquare.cpp
来自「USACO chapter one.May hope it useful to 」· C++ 代码 · 共 52 行
CPP
52 行
/*
ID: chenkai4
PROG: palsquare
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("palsquare.in");
ofstream out("palsquare.out");
#define MAXARRAY 100
char thisNum[MAXARRAY];int Nl1=0;
char square[MAXARRAY];int Nl2=0;
int base;
char cnum[21]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I'};
void changenum(char *nums,int* l,int num)
{
int n=num;
(*l)=0;
while(n)
{
nums[(*l)++]=cnum[n%base];
n/=base;
}
}
int main()
{
in>>base;
for(int a=1;a<=300;a++)
{
changenum(thisNum,&Nl1,a);
changenum(square,&Nl2,a*a);
bool palindromes=true;
for(int a=1;a<=Nl2/2;a++)
{
palindromes = palindromes && (square[a-1]==square[Nl2-a]);
}
if(palindromes)
{
for(int b=Nl1;b>=1;b--)
out<<thisNum[b-1];
out<<" ";
for(int b=Nl2;b>=1;b--)
out<<square[b-1];
out<<endl;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?