lizishi @ 2024-08-22 19:20:46
25分一直输出Impossible! #4通过,其他wa
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
void getSum(int numa[], int numb[], int len, int base, int* start) {
int ans[len + 1] = {0};
for (int i = len; i > 0; i--) {
ans[i] += numa[i] + numb[i];
if (ans[i] > base - 1) {
ans[i] -= base;
ans[i - 1]++;
}
}
for (int i = 0; i <= len; i++) {
start[i] = ans[i];
}
}
bool palindrome(int arr[], int len) {
int center = len / 2;
for (int i = 0; i < center; i++) {
if (arr[i] != arr[len - i - 1]) {
return 0;
}
}
return 1;
}
void reverse_string(int* s, int len, int* ans) {
for (int i = 0; i < len; i++) {
ans[i] = s[len - i - 1];
}
}
int main() {
int n;
char m[105];
cin >> n >> m;
int len = strlen(m);
int num[len];
for (int i = 0; i < len; i++) {
num[i] = m[i] - (m[i] < 60 ? 48 : 55);
}
for (int i = 1; i <= 30; i++) {
int temp[len];
reverse_string(num, len, temp);
int ans_temp[len];
getSum(num, temp, len, n, ans_temp);
if (palindrome(ans_temp, len)) {
cout << "STEP=" << i;
return 0;
}
}
cout << "Impossible!";
return 0;
}