質問編集履歴

2

バグを修正

2016/05/11 17:42

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,7 @@
158
158
 
159
159
  int main() {
160
160
 
161
- Direction a = Direction::FRONT;
161
+ Direction a(Direction::FRONT);
162
162
 
163
163
  std::cout << a.get() << std::endl;
164
164
 

1

Javaのコードの回転の向きがおかしかったのを修正、そもそもJavaのコードが意図した通りになっていなかったので代わりにC\+\+で記述。

2016/05/11 17:42

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -30,13 +30,13 @@
30
30
 
31
31
  public void turnRight() {
32
32
 
33
- this.value = (this.value + 1) % 4;
33
+ this.value = (this.value + 3) % 4;
34
34
 
35
35
  }
36
36
 
37
37
  public void turnLeft() {
38
38
 
39
- this.value = (this.value + 3) % 4;
39
+ this.value = (this.value + 1) % 4;
40
40
 
41
41
  }
42
42
 
@@ -70,7 +70,7 @@
70
70
 
71
71
  b.turnRight();
72
72
 
73
- System.out.println("b: " + b.get()); // b: 1
73
+ System.out.println("b: " + b.get()); // b: 2
74
74
 
75
75
  }
76
76
 
@@ -81,3 +81,93 @@
81
81
  JavaScriptとC++とGolangとPythonではそれぞれ、どのようにこのようなクラスを実装すれば良いのでしょうか?(見た目の綺麗さの面や処理速度的な面、妥協点について)
82
82
 
83
83
  4つまとめてでなくて構わないのでお聞かせ下さい。
84
+
85
+
86
+
87
+ と思っていたのですが、以上のJavaのコードは間違っていたのでC++で書いたものを載せます。すみません。
88
+
89
+ ```C++
90
+
91
+ #include <iostream>
92
+
93
+
94
+
95
+ class Direction {
96
+
97
+ public:
98
+
99
+ static const int FRONT = 0;
100
+
101
+ static const int RIGHT = 1;
102
+
103
+ static const int BACK = 2;
104
+
105
+ static const int LEFT = 3;
106
+
107
+ static const int DOWN = 0;
108
+
109
+ static const int UP = 2;
110
+
111
+ private:
112
+
113
+ int value;
114
+
115
+
116
+
117
+ public:
118
+
119
+ Direction() {
120
+
121
+ this->value = FRONT;
122
+
123
+ }
124
+
125
+ Direction(int value) {
126
+
127
+ this->value = value;
128
+
129
+ }
130
+
131
+ void turnRight() {
132
+
133
+ this->value = (this->value + 3) % 4;
134
+
135
+ }
136
+
137
+ void turnLeft() {
138
+
139
+ this->value = (this->value + 1) % 4;
140
+
141
+ }
142
+
143
+ void reverse() {
144
+
145
+ this->value = (this->value + 2) % 4;
146
+
147
+ }
148
+
149
+ int get() {
150
+
151
+ return this->value;
152
+
153
+ }
154
+
155
+ };
156
+
157
+
158
+
159
+ int main() {
160
+
161
+ Direction a = Direction::FRONT;
162
+
163
+ std::cout << a.get() << std::endl;
164
+
165
+ a.turnLeft();
166
+
167
+ std::cout << a.get() << std::endl;
168
+
169
+ return 0;
170
+
171
+ }
172
+
173
+ ```