uasco Dual Palindromes

与上题一样,改改就1Y了。

/*
ID: like_091
PROG: palsquare
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

//判断是否是回文串
bool pal(int s[], int n)
{
	bool flag = true;
	for (int i = 0; i < n; i++)
		if (s[i] != s[n - i - 1])
		{
			flag = false;
			break;
		}
	return flag;
}
int change(int n[], int x, int t)
{
	int k = 0;
	while (x > 0)
	{
		n[k++] = x % t;
		x /= t;
	}
	for (int i = 0; i < k / 2; i++)
	{
		int tem = n[i];
		n[i] = n[k - i - 1];
		n[k - i - 1] = tem;
	}
	return k;
}
int main(void)
{
	ifstream cin("palsquare.in");
	ofstream cout("palsquare.out");
	int n, s;
	while (cin>>n>>s)
	{
		int t = ++s;
		while (n)
		{
			int x[200], sum = 0;
			for (int i = 2; i <= 10; i++)
			{
				int k = change(x, t, i);
				if (pal(x, k))sum++;
			}
			if (sum >= 2)
			{
				cout<<t<<endl;
				n--;
			}
			++t;
		}
	}
	return 0;
}

原文链接: https://www.cnblogs.com/neulike/archive/2011/02/19/1958808.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    uasco Dual Palindromes

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/21205

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月7日 下午11:15
下一篇 2023年2月7日 下午11:16

相关推荐