質問編集履歴
2
問題内容の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
条件はギリシャ文字と上付き、下付き文字の変換ですなぜうまくいかないのでしょうか。
|
8
8
|
|
9
|
+
また、この機能を実現したいとき、どのようなコードを書けばよいのでしょうか
|
10
|
+
|
9
11
|
|
10
12
|
|
11
13
|
|
@@ -16,7 +18,7 @@
|
|
16
18
|
|
17
19
|
```
|
18
20
|
|
19
|
-
\alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしいが alpha x_1という出力結果になる
|
21
|
+
\alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしいが alpha x_1という出力結果になる そもそもこのコードは欠陥が多い気がします
|
20
22
|
|
21
23
|
```
|
22
24
|
|
1
コードの見易さの改善、具体的な例の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
```
|
18
18
|
|
19
|
-
|
19
|
+
\alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしいが alpha x_1という出力結果になる
|
20
20
|
|
21
21
|
```
|
22
22
|
|
@@ -42,307 +42,287 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
i
|
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
|
-
i
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
else if((*(arg+1) == '\0') || (*(arg+1) == '_')
|
124
|
-
|
125
|
-
*(arg
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
i
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
Cnt2
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
e
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
i
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
}
|
328
|
-
|
329
|
-
for(m=0; superscript[1][m] != '\0'; m++){
|
330
|
-
|
331
|
-
*(arg+4+m) = superscript[1][m];
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
else{
|
340
|
-
|
341
|
-
arg++;
|
342
|
-
|
343
|
-
}
|
344
|
-
|
345
|
-
}
|
45
|
+
int main(int argc, char *argv[]) {
|
46
|
+
|
47
|
+
if (argc > 9) {
|
48
|
+
|
49
|
+
printf("Illegal number of argument.\n");
|
50
|
+
|
51
|
+
return (-1);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
int k, a;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
for (k = 1; k < argc; k++) {
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
get_Greek_Mathsymbol(argv[k]);
|
64
|
+
|
65
|
+
get_Lgreek(argv[k]);
|
66
|
+
|
67
|
+
get_Subscript(argv[k]);
|
68
|
+
|
69
|
+
get_Superscript(argv[k]);
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
for (a = 1; a <= argc; a++) {
|
78
|
+
|
79
|
+
printf("%s\n", argv[a]);
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
return 0;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
void get_Greek_Mathsymbol(char *arg) {
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
char greek[][10] = { "alpha", "beta", "gamma", "delta", "epsilon", "zeta",
|
94
|
+
|
95
|
+
"eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "pi",
|
96
|
+
|
97
|
+
"rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega",
|
98
|
+
|
99
|
+
"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon",
|
100
|
+
|
101
|
+
"Phi", "Psi", "Omega" "geq", "leq" };
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
static int Cnt1 = 0;
|
106
|
+
|
107
|
+
int cnt1 = 0;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if (*arg == '\') {
|
112
|
+
|
113
|
+
arg++;
|
114
|
+
|
115
|
+
while (*arg != '\0') { // これをすべての文字についてループ
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if (*arg != greek[Cnt1][cnt1]) {
|
120
|
+
|
121
|
+
break;
|
122
|
+
|
123
|
+
} else if ((*(arg + 1) == '\0') || (*(arg + 1) == '_')
|
124
|
+
|
125
|
+
|| (*(arg + 1) == '^')) {
|
126
|
+
|
127
|
+
*(arg - cnt1 - 1) = '&';
|
128
|
+
|
129
|
+
if (*arg == 'q') {
|
130
|
+
|
131
|
+
*arg = '\0';
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
else {
|
140
|
+
|
141
|
+
arg++, cnt1++;
|
142
|
+
|
143
|
+
continue;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
Cnt1++;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
void get_Lgreek(char *arg) {
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
char Greek[][10] = { "Alpha", "Beta", "Gamma", "Epsilon", "Zeta", "Eta",
|
166
|
+
|
167
|
+
"Iota", "Kappa", "Mu", "Nu", "Rho", "Tau", "Chi", "omicron" };
|
168
|
+
|
169
|
+
static int Cnt2 = 0;
|
170
|
+
|
171
|
+
int i = 0;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
if ((*arg == Greek[Cnt2][0])
|
176
|
+
|
177
|
+
&& ((*(arg + 1) == '\0') || (*(arg + 1) == '_')
|
178
|
+
|
179
|
+
|| (*(arg + 1) == '^'))) {
|
180
|
+
|
181
|
+
*arg = '&';
|
182
|
+
|
183
|
+
arg++;
|
184
|
+
|
185
|
+
while (Greek[Cnt2][i] != '\0') {
|
186
|
+
|
187
|
+
*arg = Greek[Cnt2][i];
|
188
|
+
|
189
|
+
arg++, i++;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
Cnt2++;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
void get_Subscript(char *arg) {
|
202
|
+
|
203
|
+
char rest1[10];
|
204
|
+
|
205
|
+
int i, j, l, m;
|
206
|
+
|
207
|
+
int cnt2 = 0;
|
208
|
+
|
209
|
+
char subscript[][10] = { "<sub>", "</sub>" };
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
if (*arg == '_') {
|
214
|
+
|
215
|
+
arg++;
|
216
|
+
|
217
|
+
for (i = 0; i <= 9; i++) {
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
if ((*arg == '\0') || (*arg == '^')) {
|
222
|
+
|
223
|
+
break;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
rest1[i] = *arg;
|
228
|
+
|
229
|
+
arg++, cnt2++;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
for (j = 0; subscript[0][j] != '\0'; j++) {
|
236
|
+
|
237
|
+
*(arg - cnt2 - 1 + j) = subscript[0][j];
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
for (l = 0; l < cnt2; l++) {
|
242
|
+
|
243
|
+
*(arg - cnt2 + 4 + l) = rest1[l];
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
for (m = 0; subscript[1][m] != '\0'; m++) {
|
248
|
+
|
249
|
+
*(arg + 4 + m) = subscript[1][m];
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
} else {
|
254
|
+
|
255
|
+
arg++;
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
void get_Superscript(char *arg) {
|
266
|
+
|
267
|
+
char rest2[10];
|
268
|
+
|
269
|
+
int i, j, l, m;
|
270
|
+
|
271
|
+
int cnt3 = 0;
|
272
|
+
|
273
|
+
char *superscript[] = { "<sup>", "</sup>" };
|
274
|
+
|
275
|
+
if (*arg == '_') {
|
276
|
+
|
277
|
+
arg++;
|
278
|
+
|
279
|
+
for (i = 0; i <= 9; i++) {
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if (*arg == '\0') {
|
284
|
+
|
285
|
+
break;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
rest2[i] = *arg;
|
290
|
+
|
291
|
+
arg++, cnt3++;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
for (j = 0; superscript[0][j] != '\0'; j++) {
|
298
|
+
|
299
|
+
*(arg - cnt3 - 1 + j) = superscript[0][j];
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
for (l = 0; l < cnt3; l++) {
|
304
|
+
|
305
|
+
*(arg - cnt3 + 4 + l) = rest2[l];
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
for (m = 0; superscript[1][m] != '\0'; m++) {
|
310
|
+
|
311
|
+
*(arg + 4 + m) = superscript[1][m];
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
} else {
|
318
|
+
|
319
|
+
arg++;
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
346
326
|
|
347
327
|
```
|
348
328
|
|