卷王 @ 2022-10-30 20:58:20
#include <bits/stdc++.h>
using namespace std;
int n, step = 0;
int len;
string s1, s2;
inline void work() //计算s2并累加
{
for(int i = 0; i < len; i++)
s2[len-i-1] = s1[i];
len += 2;
for(int i = 0; i < len; i++)
{
s1[i] = s1[i] + s2[i];
s1[i+1] += s1[i] / n;
s1[i] %= n;
}
while(!s1[len-1]) len--;
}
inline bool check() //判断是否是回文数
{
for(int i = 0; i < len / 2; i++)
if(s1[i] != s1[len-i-1]) return false;
else return true;
}
int main()
{
cin >> n >> s1;
len = s1.size();
for(int i = 0; i < len; i++)
{
if(s1[i] >= '0' && s1[i] <= '9') s1[i] = s1[i] - '0';
else s1[i] = s1[i] - 'A' + 10;
}
while(check() == false)
{
step++;
if(step > 30) break;
work();
}
if(step <= 30) cout << "STEP=" << step;
else cout << "Impossible!";
return 0;
}
by 卷王 @ 2022-10-30 20:59:51
按照第
是因为不能用
by tommyfj @ 2022-10-30 21:31:25
@holdyhao_Genius
else return true;
改成 return true;
试试
by tommyfj @ 2022-10-31 22:38:49
@holdyhao_Genius
by 卷王 @ 2022-11-02 20:43:26
@tommyfj 是有这个问题,可是提交上去也只有
by 卷王 @ 2022-11-02 20:44:11
@tommyfj 顺便说下,我看您的回复的时候差点看成我自己了()()()
by tommyfj @ 2022-11-02 20:52:27
@holdyhao_Genius 再开个 O2 就过了