# On palindrome number

Time：2021-3-27

### Title Description

For a natural number n, if the number N1 obtained by inversing the digits of n is equal to N, then n is called palindrome number, such as 2332.
If given an n (2 < = n < = 16) base number m (the length of M is less than 100 bits), if M is not palindrome number, it can be added in N base to get palindrome number.
For example, for the decimal number 79
STEP1 : 79 + 97 = 176
STEP2 : 176 + 671 = 847
STEP3 : 847 + 748 = 1595
STEP4 : 1595 +5951 = 7546
STEP5 : 7546 + 6457 = 14003
STEP6 : 14003 + 30041 = 44044
Then, for a given n-ary number m, please judge whether it can get palindrome number within 30 steps (including 30 steps).

Input format:
The first line contains a positive integer n (2 < = n < = 16).
The second line contains a positive integer m (within 100 bits).

Output format:
If the palindrome number can be obtained in N steps, output “Step = n”, otherwise output “no”.

### Thinking of solving problems

1. Store high precision numbers in array (special judgment for hexadecimal numbers)
2. Reverse arrangement, judge whether it is palindrome number
3. If it is not palindrome number, high-precision n-ary addition is carried out
4. Cycle 2-3 steps until the conditions are met

### Complete code

``````#include
#include
#define MAX_LEN 1000
char num[MAX_LEN + 10];
int sz1[MAX_LEN + 10];
int sz2[MAX_LEN + 10];

void reverse(int a[], int b[]) {
int i;
for (i = 1; i <= a; i++) {
b[i] = a[a - i + 1];
}
b = a;
}/*Function: reverse arrangement*/

int cmp(int a[], int b[]) {
int i;
for (i = 1; i <= a / 2; i++) {
if (a[i] != b[i]) {
return 0;
}
}
return 1;
}/*Function: judge palindrome number
Return value: return 0 for non palindrome number, return 1 for palindrome number*/

void plus(int a[], int b[], int n) {
int i;
for (i = 1; i <= a; i++) {
a[i] += b[i];
a[i + 1] += a[i] / n;
a[i] %= n;
}
if (a[a + 1] > 0) {
a++;
}

int main()
{
int N, i;
scanf("%d", &N);
scanf("%s", num);

sz1 = strlen(num);
for (i = 1; i <= sz1; i++) {
if (num[sz1 - i] >= 'A' && num[sz1 - i] <= 'F') {
sz1[i] = num[sz1 - i] - 'A' + 10;
}
else if (num[sz1 - i] >= 'a' && num[sz1 - i] <= 'f') {
sz1[i] = num[sz1 - i] - 'a' + 10;
else {
sz1[i] = num[sz1 - i] - '0';
}
}
for (i = 0; i <= 30; i++) {
reverse(sz1, sz2);
if (cmp(sz1, sz2) == 1) {
break;
}
plus(sz1, sz2, N);
}

if (i <= 30) {
printf("STEP=%d", i);
}
else {
printf("NO");
}
return 0;
}``````

## Introduce regular expressions in ruby in detail

A regular expression is a special sequence of characters that matches or finds other strings or collections of strings by using patterns with special syntax. grammar A regular expression is literally a pattern between slashes or any separator after% R, as follows: ? 1 2 3 4 5 6 7 8 9 10 11 12 […]