質問編集履歴

1

ソースコードを記載しました

2019/05/06 04:49

投稿

naberyo
naberyo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,126 @@
1
+ `/**************************/
2
+
3
+ /* オイラーの一筆書き    */
4
+
5
+ /* euler.c      */
6
+
7
+ /**************************/
8
+
9
+ #include <stdio.h>
10
+
11
+ #include <stdlib.h>
12
+
13
+
14
+
15
+ #define NMAX 100 //点の数の上限
16
+
17
+ #define EDGEMAX 100 //線の数の上限
18
+
19
+ int adjacent [NMAX + 1][NMAX + 1]; //隣接行列
20
+
21
+ int position [EDGEMAX + 1] ; //線の数
22
+
23
+ int n, n_edge, edge, solution;//点、線の数、線、解の番号
24
+
25
+
26
+
27
+ void readgraph(void) //データ入力
28
+
29
+ {
30
+
31
+ int i, j;
32
+
33
+
34
+
35
+ if (scanf("%d%*[^\n]", &n) != 1 || n > NMAX) //点の数
36
+
37
+ { n = 0; return;
38
+
39
+ }
40
+
41
+ for (i = 1; i <= n; i++)
42
+
43
+ for (j = 1; j <= n ; j++) adjacent[i][j]= 0;
44
+
45
+ while (scanf("%d%d%*[^\n]" ,&i, &j) == 2) {
46
+
47
+ n_edge++; //線の数
48
+
49
+ adjacent[i][j]++;
50
+
51
+ adjacent[j][i]++;
52
+
53
+ }
54
+
55
+ printf("rinnsetu gyouretsu:\n");
56
+
57
+ for (i = 1 ; i <= n; i++) {
58
+
59
+ for(j=1; j <= n; j++) printf("%d",adjacent[i][j]);
60
+
61
+ printf("\n");
62
+
63
+ }
64
+
65
+ }
66
+
67
+ void visit(int i)
68
+
69
+ {
70
+
71
+ int j;
72
+
73
+ position[edge] = i;
74
+
75
+ if (edge == n_edge) {
76
+
77
+ printf("kai %d:", ++solution);
78
+
79
+ for (i = 0 ; i <= n_edge; i++) printf(" %d" , position[i]);
80
+
81
+ printf("\n");
82
+
83
+ } else {
84
+
85
+ for ( j = 1; j <= n; j++) if(adjacent[i][j]) {
86
+
87
+ adjacent[i][j]--;
88
+
89
+ adjacent[j][i]--; //有向グラフならこの行は削除
90
+
91
+ edge++; visit(j); edge--;
92
+
93
+ adjacent[i][j]++;
94
+
95
+ adjacent[j][i]++; //有向グラフならこの行は
96
+
97
+ }
98
+
99
+ }
100
+
101
+
102
+
103
+ }
104
+
105
+ int main()
106
+
107
+ {
108
+
109
+ readgraph(); //データを読む
110
+
111
+ solution = edge = 0; visit(1);//点1から出発
112
+
113
+ if(solution== 0) printf("kai nasi\n");
114
+
115
+ return EXIT_SUCCESS;
116
+
117
+ }
118
+
119
+
120
+
121
+ コード
122
+
1
- 当方プログラム初心者でvisual studio codeを用いてc言語の勉強をしております
123
+ ```当方プログラム初心者でvisual studio codeを用いてc言語の勉強をしております
2
124
 
3
125
  txtファイルを読ませるプログラムの実行のやり方がわからず困っております。
4
126
 
@@ -54,6 +176,32 @@
54
176
 
55
177
 
56
178
 
179
+ また
180
+
181
+ PS C:\c program> gcc euler.c
182
+
183
+ PS C:\c program> .\a.exe < graph.cと実行すると
184
+
185
+ 発生場所 行:1 文字:9
186
+
187
+ + .\a.exe < graph.c
188
+
189
+ + ~
190
+
191
+ 演算子 '<' は、今後の使用のために予約されています。
192
+
193
+ + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
194
+
195
+ + FullyQualifiedErrorId : RedirectionNotSupported
196
+
197
+
198
+
199
+
200
+
57
201
  ネットで調べたのですが具体的な方法が分からず
58
202
 
59
203
  正しいファイルの読み込み方法を教えて頂けたら幸いです。
204
+
205
+
206
+
207
+ ソースコードを載せさせて頂きました、よろしくお願いいたします。