#include<iostream>
#include<string>
using namespace std;
int n;
string sub(string s)
{
string m;
for (int i = s.length() - 1; i >= 0; i--)
{
m += s[i];
}
return m;
}
void fund(int num, int m, string s, bool b)
{
if (num <= 2)
{
if (m < 0)
return;
if (num == 1)
{
if (m < 10)
{
char a = m + '0';
string l = sub(s);
s += a;
s += l;
cout << s << endl;
}
}
else
{
if (m <= 18 && m % 2 == 0)
{
char a = m / 2 + '0';
string l = sub(s);
s += a;
s += a;
s += l;
cout << s << endl;
}
}
return;
}
int i;
if (b == false)
{
i = 1;
}
else
i = 0;
for (; i < 10; i++)
{
m -= 2 * i;
char a = i + '0';
s += a;
fund(num - 2, m, s, true);
s = s.substr(0, s.size() - 1);
m += 2 * i;
}
}
int main()
{
cin >> n;
if (n < 5 || n>54)
{
cout << -1;
return 0;
}
string s = "";
fund(5, n, s, false);
fund(6, n, s, false);
return 0;
}
回文数字(递归求解,又臭又长,慎点)
最新推荐文章于 2023-05-16 21:00:33 发布