AIBEYOND @ 2023-07-22 16:34:09
#include <iostream>
#include <string.h>
using namespace std;
void add(char M[], int N) //十进制以内
{
char M1[108];
strcpy(M1, M);
strrev(M1);
int c = 0;
for (int i = 0;M1[i] != '\0' || c == 1;i++)
{
if (c == 1 && M1[i] == '\0')
{
M[i] = 1 + '0';
M[i + 1] = '\0';
break;
}
if ((M1[i] - '0') + (M[i] - '0') + c >= N)
{
M[i] = ((M[i] - '0') + (M1[i] - '0') - N + c) + '0';
c = 1;
}
else
{
M[i] = ((M[i] - '0') + (M1[i] - '0') + c) + '0';
c = 0;
}
}
}
void add16(char M[]) //十六进制
{
char M1[108];
strcpy(M1, M);
strrev(M1);
int c = 0;
for (int i = 0;M1[i] != '\0' || c == 1;i++)
{
if (c == 1 && M1[i] == '\0')
{
M[i] = 1 + '0';
M[i + 1] = '\0';
break;
}
if (int(M[i]) <= 57 && int(M1[i]) <= 57)
{
if (((int(M[i])) - 48) + ((int(M1[i])) - 48) + c <= 9)
{
M[i] = char(((int(M[i])) - 48) + ((int(M1[i])) - 48) + c + 48);
c = 0;
}
else if (((int(M[i])) - 48) + ((int(M1[i])) - 48) + c <= 15)
{
M[i] = char(((int(M[i])) - 48) + ((int(M1[i])) - 48) + c + 55);
c = 0;
}
else
{
M[i] = char(((int(M[i])) - 48) + ((int(M1[i])) - 48) + c + 55);
c = 1;
}
}
else if (int(M1[i]) >= 65 && int(M[i]) >= 65)
{
if (((int(M[i])) - 55) + ((int(M1[i])) - 55) + c - 16 <= 9)
{
M[i] = char(((int(M[i])) - 55) + ((int(M1[i])) - 55) + c - 16 + 48);
c = 1;
}
else
{
M[i] = char(((int(M[i])) - 55) + ((int(M1[i])) - 55) + c - 16 + 55);
c = 1;
}
}
else
{
if (((int(M[i])) - 48) + ((int(M1[i])) - 55) + c <= 15)
{
M[i] = char(((int(M[i])) - 48) + ((int(M1[i])) - 55) + c + 55);
c = 0;
}
else
{
M[i] = char(((int(M[i])) - 48) + ((int(M1[i])) - 55) + c - 16 + 48);
c = 1;
}
}
}
}
int main()
{
int N;
char M[108];
cin >> N;
cin >> M;
int i;
char L[108];
for (i = 0;i <= 29;i++)
{
if (N <= 10)
{
add(M, N);
}
else
{
add16(M);
}
strcpy(L, M);
strrev(L);
if (strcmp(L, M) == 0)
{
break;
}
}
if (i <= 29)
{
cout << "STEP=" << i + 1;
}
else
{
cout << "Impossible!";
}
return 0;
}
by Smile_love @ 2023-07-22 16:35:50
不会吧
by Smile_love @ 2023-07-22 16:36:51
/tmp/compiler_6q2t7j83/src: 在函数‘void add(char*, int)’中:
/tmp/compiler_6q2t7j83/src:8:5: 错误:‘strrev’ was not declared in this scope; did you mean ‘strsep’?
8 | strrev(M1);
| ^~~~~~
| strsep
/tmp/compiler_6q2t7j83/src: 在函数‘void add16(char*)’中:
/tmp/compiler_6q2t7j83/src:34:5: 错误:‘strrev’ was not declared in this scope; did you mean ‘strsep’?
34 | strrev(M1);
| ^~~~~~
| strsep
/tmp/compiler_6q2t7j83/src: 在函数‘int main()’中:
/tmp/compiler_6q2t7j83/src:109:9: 错误:‘strrev’ was not declared in this scope; did you mean ‘strsep’?
109 | strrev(L);
| ^~~~~~
| strsep
by DioxygenDifluoride @ 2023-07-22 16:50:36
@AIBEYOND strrev
不是标准函数
by DioxygenDifluoride @ 2023-07-22 16:51:08
@AIBEYOND 请自己手写
by AIBEYOND @ 2023-07-22 17:16:54
@woshishabi250 ok,谢谢大佬
by AIBEYOND @ 2023-07-22 17:17:18
@Smile_love 谢谢大佬