bonjour,
je suis a la recherche d'un code source en C du Jeu Futoshiki,
j'ai beaucoup essayé seul mais toujours ça marche pas.
Merci de m'aider
Version imprimable
bonjour,
je suis a la recherche d'un code source en C du Jeu Futoshiki,
j'ai beaucoup essayé seul mais toujours ça marche pas.
Merci de m'aider
Plutôt que de chercher un code tout fait, pourquoi ne pas nous montrer ta solution et nous dire ce qui ne marche pas ?
bonjour
ci-dessous ma code source, mais toujours ça marche pas :(
Code:
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 #include <stdio.h> #include <stdlib.h> #include <string.h> char **readmat(int *n); void print(char **mat,int n); int check(char **mat,int n); int expand (char **mat,int n,int i); int main(int argc, char *argv[]) { char **mat; int n, j; mat=readmat(&n); if(mat == NULL) return 1; if(check(mat,n)){ print(mat,n); } else if(expand(mat,n,0)==1){ print(mat,n); } else { printf("Nessuna soluzione trovata.\n"); } for(j=0; j<=n;j++) free(mat[j]); free(mat); system("PAUSE"); return 0; } char **readmat(int *n){ FILE *fp; char *line,nome[100]; int i,j,k; char **mat; printf("Inserire il nome del file: "); scanf("%s",nome); fp=fopen(nome,"r"); if(fp==NULL){ printf("Errore apertura file"); return NULL; } if(fgets(nome,100,fp)==NULL){ printf("Formato file non valido\n"); fclose(fp); return NULL; } if(sscanf(nome,"%d",n)!=1){ printf("Errore nei parametri del file\n"); fclose(fp); return NULL; } (*n)=(((*n)*2)-1); mat=(char**)malloc((*n)*sizeof(char*)); for(i=0;i<=(*n);i++) mat[i]=(char*)malloc((*n)*sizeof(char)); line=(char*)malloc(2*(*n)*sizeof(char)); i=0; while(i<=2*(*n) && fgets(line,2*(*n)+2,fp)!=NULL){ j=0; k=0; while(j<=2*(*n)){ if(line[j]!=' '){ mat[i][k]=line[j]; k++; } j++; } i++; } return mat; //print(mat, (*n)); } void print(char **mat,int n){ int i=0,j=0; for (i=0; i<n; i++) { for (j=0; j<n; j++) { printf("%c", mat[i][j]); } printf("\n"); } } int check(char **mat,int n) { int i,j; int k=1; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(mat[i][j]=='<'){ if(mat[i][j-1] >= mat[i][j+1]) k=0; } else if(mat[i][j]=='>'){ if(mat[i][j-1] <= mat[i][j+1]) k=0; } else if(mat[i][j]=='^'){ if(mat[i-1][j] >= mat[i+1][j]) k=0; } else if(mat[i][j]=='v'){ if(mat[i-1][j] <= mat[i+1][j]) k=0; } } } return k; } int expand (char **mat,int n,int i) { int j=i/n; int k=i%n; int p; if(i>=n*n) { return 1; } else{ if((mat[j][k]>47)&&(mat[j][k]<58)){ if(mat[j][k]=='0'){ expand(mat,n,i+2); } for (p=(mat[j][k]-48); p<(10-(mat[j][k]-48)); p++) { mat[j][k]=48+p; if (check(mat,i)) { if (expand(mat, n, i+2)) { return 1; } } } i-=2; mat[j][k]='0'; } } return 0; }
Met ton code entre les balises [CODE] et dit nous ce qui ne marche pas d'après tes tests. Ou alors est-ce que c'est à la compilation ? Soit précis.