回答編集履歴
6
コードのバグ修正
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
else // number, parentheses or unary operators
|
64
64
|
|
65
|
-
get() == '.' || isdigit(c) ? iss.unget(), iss >> v
|
65
|
+
get() == '.' || isdigit(c) ? iss.unget(), iss >> v ? get() : (c = 3):
|
66
66
|
|
67
67
|
c == '(' ? v = expr("+-*/^^"), c == ')' ? get() : (c = 2) :
|
68
68
|
|
@@ -89,3 +89,7 @@
|
|
89
89
|
}
|
90
90
|
|
91
91
|
```
|
92
|
+
|
93
|
+
### 追記
|
94
|
+
|
95
|
+
3 + . + 5 がエラーにならないバグがあったの修正しました。
|
5
コードの修正
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
private:
|
44
44
|
|
45
|
-
int get() {
|
45
|
+
int get() { return iss >> c ? c : (c = 0); }
|
46
46
|
|
47
47
|
double expr(const char *b) {
|
48
48
|
|
4
コードの変更
test
CHANGED
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
string s;
|
86
86
|
|
87
|
-
while (cout << ">> ", getline(cin, s) && s
|
87
|
+
while (cout << ">> ", getline(cin, s) && s != ".") Stack t(s);
|
88
88
|
|
89
89
|
}
|
90
90
|
|
3
コードの追加
test
CHANGED
File without changes
|
2
cout.precision(15); を追加
test
CHANGED
@@ -33,6 +33,8 @@
|
|
33
33
|
Stack(const string& s) : iss(s) {
|
34
34
|
|
35
35
|
double v = expr("+-*/^^");
|
36
|
+
|
37
|
+
cout.precision(15);
|
36
38
|
|
37
39
|
c ? cout << " error\n" : cout << " " << v << "\n";
|
38
40
|
|
1
コメント訂正
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
#include <string> // getline
|
16
16
|
|
17
|
-
#include <cctype> // isdigit
|
17
|
+
#include <cctype> // isdigit
|
18
18
|
|
19
19
|
#include <cmath> // pow
|
20
20
|
|