dualpal.cpp

来自「USACO chapter one.May hope it useful to 」· C++ 代码 · 共 76 行

CPP
76
字号
/*
ID: chenkai4
PROG: dualpal
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("dualpal.in");
ofstream out("dualpal.out");
#define MAXARRAY 10000

int N,S;

struct _int
{
	int l,b[MAXARRAY];
	int base;
	_int(int n=0,int Base =10)
	{
		base = Base;
		l=0;memset(b,0,sizeof(b));
		while(n)
		{
			b[l++]=n%base;
			n/=base;
			if(b[l])l++;
		}
	}
	_int& carry()
	{
		for(int a=0;a<l;a++)
		{
			b[a+1]+=b[a]/base;
			b[a]%=base;
			if(b[l])l++;
		}
		return *this;
	}
};

bool pan(_int how)
{
	for(int a=0;a<=(how.l-1)/2;a++)
		if(how.b[a]!=how.b[how.l-1-a])
			return false;
	return true;
}

bool isPalindrome(int which)
{
	int count=0;
	for(int a=2;a<=10;a++)
	{
		_int thisone(which,a);
		if(pan(thisone))
			count++;
	}
	if(count>=2)
		return true;
	else
		return false;
}

int main()
{
	in>>N>>S;
	int count=0;
	while(count<N)
	{
		S++;
		if(isPalindrome(S))
		{out<<S<<endl;count++;}
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?