经典简单题,数独+迷宫,初始的数独为:
输入的格式为flag{xxx},长度应该为70
uint32_t flagLength = strlen(flag);
if (flagLength != 70) {
printf("Try again!\n");
return -1;
}
前56个数值用于填写数独,从左到右从上到下依次填充数独。填充后验证数独的正确性:
uint32_t idx = 0;
for (uint32_t i = 0; i < 9; ++i) {
for (uint32_t j = 0; j < 9; ++j) {
if (sudoku[i][j] == 0xF) {
if (mflag[idx] < '0' || mflag[idx] > '9') {
printf("Try again!\n");
return -1;
}
sudoku[i][j] = mflag[idx++] - '0';
}
}
}
uint32_t m = 1, n = 1;
for (uint32_t i = 0; i < 9 && m == 1; i++) {
for (uint32_t j = 0; j < 9 && m == 1; j++) {
for (uint32_t k = j + 1; k < 9; k++) {
if (sudoku[i][j] != sudoku[i][k]) {
m = 1;
}
else {
m = 0;
break;
}
}
}
}
for (uint32_t i = 0; i < 9 && n == 1; i++) {
for (uint32_t j = 0; j < 9 && n == 1; j++) {
for (uint32_t k = j + 1; k < 9; k++) {
if (sudoku[j][i] != sudoku[k][i]) {
n = 1;
}
else {
n = 0;
break;
}
}
}
}
数独验证成功后,进入下一阶段的简单迷宫,迷宫图如下:
if (m == 1 && n == 1) {
uint8_t maze[4][4] = {
'!', '-', '?', '+',
'+', '+', '-', '+',
'-', '+', '+', '+',
'+', '-', '-', '+',
};
其中感叹号为起点,问号为终点,加号表示可以通行,减号表示不能同行,WASD分别表示上左下右,要求输入的后8个数值能够到达迷宫的终点,且每一步的过程中不能触碰到减号以及地图边界:
uint8_t x = 0, y = 0; // SDSDDWWA
for (uint32_t i = 0; i < 8; ++i) {
switch (mflag[idx++])
{
case 'W':
if (x == 0) {
printf("Try again!\n");
return -1;
}
x -= 1;
break;
case 'A':
if (y == 0) {
printf("Try again!\n");
return -1;
}
y -= 1;
break;
case 'S':
if (x == 3) {
printf("Try again!\n");
return -1;
}
x += 1;
break;
case 'D':
if (y == 3) {
printf("Try again!\n");
return -1;
}
y += 1;
break;
default:
break;
}
if (maze[x][y] == '-') {
printf("Try again!\n");
return -1;
}
}
if (maze[x][y] == '?') {
printf("You are winner!\n");
return 0;
}
第一步识别数独并想办法求解数独,解数独得到的56位数据如下:
34689155813271746868579324125982187492581517263447389126
第二步识别迷宫,并找到那唯一到终点的路,走法为:SDSDDWWA
所以最终的Flag为:
flag{34689155813271746868579324125982187492581517263447389126SDSDDWWA}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
最后于 2024-10-1 15:59
被kanxue编辑
,原因: