Add tags

Add tags to the following comment

C言語初心者なんでうまく実行できません。座標を読み込むテキストファイルの読み込み方がよくわかりません。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>

#define START 8
#define GOAL 1
#define ROUTE 100
#define END -1
int maze[6][6];
const int y_goal = 5, x_goal =2;
int route[ROUTE][2];
int rp = 0;
int solvemaze(int y, int x) {
    static int success = 0;
    if(y==y_goal && x==x_goal)success == GOAL;
    maze[y][x] = 'T';
    if(!success && maze[y-1][x] == '0'){solvemaze(y-1, x);}
    if(!success && maze[y][x+1] == '0'){solvemaze(y, x+1); }
    if(!success && maze[y][x-1] == '0'){solvemaze(y, x-1); }
    if(!success && maze[y+1][x] == '0'){solvemaze(y+1, x); }
    if(success) {
        route[rp][0] = y;
        route[rp][1] = x;
        rp++;
    }
    return success;
}

void maze_print() {
    int i, j;
    for(i=0; i<6; i++) {
        for(j=0; j<6;j++) {
            printf("%d", maze[j][i]);
        }
        printf("\n");
    }
}

int main() {
    int i;
    maze_print(); printf("\n");
    solvemaze(1,1);
    maze_print(); printf("\n");
    for(i=rp; i; i--) {
        printf("%d.", route[i-1][0]);
        printf("%d", route[i-1][1]);
    }
    putchar('\n');
    return 0;
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...