wodheier @ 2022-06-20 19:22:17
源码如下:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
bool hui(vector<int>);
bool hui(vector<int>a)
{
vector<int> s = a;
reverse(s.begin(), s.end());
return s == a;
}
void jia(vector<int>&, int);
void jia(vector<int>& a, int n)
{
vector<int>d = a;
reverse(d.begin(), d.end());
int b = 0;
for (int i = 0; i < a.size(); i++)
{
a[i] = a[i] + d[i] + b;
if (a[i] >= n)
{
b = a[i] / n;
a[i] %= n;
}
else
b = 0;
}
if (b)
{
a.push_back(b);
b = 0;
}
}
bool hui(string);
bool hui(string a)
{
string s = a;
reverse(s.begin(), s.end());
return a == s;
}
int main()
{
int n, m,s=0;
cin >> n;
if (n < 16)
{
cin >> m;
vector<int>a;
int b = m % 10, c = m / 10;
while (c != 0)
{
a.push_back(b);
b = c % 10, c /= 10;
}
a.push_back(b);
if (hui(a))
{
cout << "STEP=" << s; return 0;
}
while (!hui(a))
{
jia(a, n);
s++;
if (s > 30)
break;
}
if (s > 30)
{
cout << "Impossible!";
}
else
cout << "STEP=" << s;
}
else
{
cin.get();
string a;
getline(cin, a);
int f = 0;
if (hui(a))
{
cout << "STEP=" << "0";
}
else
{
vector<int>r;
for (int i = 0; i < a.size(); i++)
{
if (int(a[i] > 64))
{
r.push_back(int(a[i]) - 55);
}
else
{
r.push_back(int(a[i]) - 48);
}
}
while (!hui(r))
{
jia(r, 16);
f++;
if (f > 30)
break;
}
if (f > 30)
{
cout << "Impossible!";
}
else
cout << "STEP=" << f;
}
}
}
输入:16\nAC27 我在Windows10的VS2019上测出来的结果是:“STEP=6”,在洛谷上就是不对!我应该没用linux的关键词吧?
by I_wil_ak_IOI @ 2022-06-20 19:24:52
小心\r\n