なんの工夫もない力技版です。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NDIRS 4
const char *str = "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"abcdefghijklmnopqrstuvwxyz" \
"01234567";
int dirs[NDIRS][60] = {
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, -1, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
-1, 34, 35, -1, 37, 38, -1, 40, 41, -1, 43, 44, -1, 46, 47, -1,
49, 50, -1, 52, 53, -1, 55, 56, -1, 58, 59, -1
},
{
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, 59, 58,
57, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 32, 31, 30
},
{
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, -1, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, -1, 33, 34, -1, 36, 37, -1, 39, 40, -1, 42, 43, -1, 45, 46,
-1, 48, 49, -1, 51, 52, -1, 54, 55, -1, 57, 58
},
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
}
};
void solve(char *r, const char *s)
{
int next;
int step;
int dir;
int pos;
int i;
step = 0;
dir = 0;
pos = 0;
*r++ = str[pos + 1];
for (; *s != '\0'; s++) {
if (*s == 'R')
dir = (dir + 1) % NDIRS;
else if (*s == 'L')
dir = (dir - 1 + NDIRS) % NDIRS;
else if (*s >= '0' && *s <= '9')
step = *s - '0';
else if (*s >= 'a' && *s <= 'f')
step = *s - 'a' + 10;
for (; step > 0; step--) {
next = dirs[dir][pos];
*r++ = str[next + 1];
if (next == -1)
goto end;
for (i = 0; i < NDIRS; i++) {
if (dirs[i][next] == pos) {
dir = (i + 2) % NDIRS;
break;
}
}
pos = next;
}
}
end:
*r = '\0';
}
void test(const char *in, const char *out)
{
char r[80];
solve(r, in);
printf("%s -> %s(%s) %s\n", in, r, out,
strcmp(r, out) == 0 ? "ok" : "ng");
}
int main(void)
{
/*0*/ test( "2RcL3LL22", "ABCNYjmpsvy147edcbcdef" );
...snip...
return 0;
}