teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

7

コード修正

2020/07/11 06:22

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -13,11 +13,13 @@
13
13
 
14
14
  ---
15
15
  `bounding_rectangle()`の以下の箇所で`area[0]`が最小値の場合、`ri`が不定値となり範囲外アクセスが発生します。
16
+ `i`が`0`の場合は条件成立しないのは明らかなので、`i`は`1`開始で良いですね。
16
17
  ```diff
17
18
  double min_area = area[0];
18
19
  - int ri;
19
- + int ri=0;
20
+ + int ri = 0;
20
- for (i = 0; i < n; i++) {
21
+ - for (i = 0; i < n; i++) {
22
+ + for (i = 1; i < n; i++) {
21
23
  if (min_area > area[i]) {
22
24
  min_area = area[i];
23
25
  ri = i;

6

文言修正

2020/07/11 06:22

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  > kadai31.cpp:114:44: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'Point')
2
2
 
3
3
  `Point`を`std::cout`(`std::basic_ostream<char>`)にどう出力すればいいかわからないからです。
4
- 以下を追加してください。
4
+ `Point`構造体の定義より後に以下を追加してください。
5
5
  出力の書式はお好きなように変更してください。
6
6
  ```C++
7
7
  std::ostream& operator<<(std::ostream& stream, const Point& point)

5

文言修正

2020/07/11 05:51

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  `Point`を`std::cout`(`std::basic_ostream<char>`)にどう出力すればいいかわからないからです。
4
4
  以下を追加してください。
5
+ 出力の書式はお好きなように変更してください。
5
6
  ```C++
6
7
  std::ostream& operator<<(std::ostream& stream, const Point& point)
7
8
  {

4

コード修正

2020/07/11 05:48

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -3,7 +3,7 @@
3
3
  `Point`を`std::cout`(`std::basic_ostream<char>`)にどう出力すればいいかわからないからです。
4
4
  以下を追加してください。
5
5
  ```C++
6
- std::ostream& operator<<(std::ostream& stream, const Point point)
6
+ std::ostream& operator<<(std::ostream& stream, const Point& point)
7
7
  {
8
8
  stream << '(' << point.x << ',' << point.y << ')';
9
9
  return stream;

3

文言修正

2020/07/11 05:46

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -1,6 +1,6 @@
1
1
  > kadai31.cpp:114:44: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'Point')
2
2
 
3
- `Point`を`std::cout`にどう出力すればいいかわからないからです。
3
+ `Point`を`std::cout`(`std::basic_ostream<char>`)にどう出力すればいいかわからないからです。
4
4
  以下を追加してください。
5
5
  ```C++
6
6
  std::ostream& operator<<(std::ostream& stream, const Point point)

2

文言修正

2020/07/11 05:42

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -1,3 +1,5 @@
1
+ > kadai31.cpp:114:44: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'Point')
2
+
1
3
  `Point`を`std::cout`にどう出力すればいいかわからないからです。
2
4
  以下を追加してください。
3
5
  ```C++

1

文言修正

2020/07/11 05:41

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -9,7 +9,7 @@
9
9
  ```
10
10
 
11
11
  ---
12
- `bounding_rectangle()`の以下の箇所で`area[0]`が最小値の場合、不定値となり範囲外アクセスが発生します。
12
+ `bounding_rectangle()`の以下の箇所で`area[0]`が最小値の場合、`ri`が不定値となり範囲外アクセスが発生します。
13
13
  ```diff
14
14
  double min_area = area[0];
15
15
  - int ri;