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

回答編集履歴

3

微修正

2020/07/21 08:02

投稿

episteme
episteme

スコア16612

answer CHANGED
@@ -70,7 +70,7 @@
70
70
  std::sort((point*)data, (point*)data+5*7,
71
71
  [](const point& a, const point& b) {
72
72
  return a.hori_angle < b.hori_angle ||
73
- (!(a.hori_angle < b.hori_angle ) && a.vertical_angle < b.vertical_angle);
73
+ (!(b.hori_angle < a.hori_angle ) && a.vertical_angle < b.vertical_angle);
74
74
  });
75
75
 
76
76
  // できたかな?

2

追記

2020/07/21 08:02

投稿

episteme
episteme

スコア16612

answer CHANGED
@@ -53,4 +53,32 @@
53
53
  std::cout << std::endl;
54
54
  }
55
55
  }
56
+ ```
57
+ [追記] 第三版
58
+ ```C++
59
+ #include <iostream>
60
+ #include <algorithm>
61
+
62
+ class point {
63
+ public:
64
+ double hori_angle; //xy平面上でのx軸と点の角度(以下、水平角)
65
+ double vertical_angle; //xy平面と点のなす角度(以下、垂直角)
66
+ };
67
+
68
+ int main() {
69
+ point data[5][7] = { ... };
70
+ std::sort((point*)data, (point*)data+5*7,
71
+ [](const point& a, const point& b) {
72
+ return a.hori_angle < b.hori_angle ||
73
+ (!(a.hori_angle < b.hori_angle ) && a.vertical_angle < b.vertical_angle);
74
+ });
75
+
76
+ // できたかな?
77
+ for ( int row = 0; row < 5; ++row ) {
78
+ for ( int col = 0; col < 7; ++col ) {
79
+ std::cout << data[row][col].hori_ange << ',' << data[row][col].vertical_angle << ' ';
80
+ }
81
+ std::cout << std::endl;
82
+ }
83
+ }
56
84
  ```

1

追記

2020/07/21 07:33

投稿

episteme
episteme

スコア16612

answer CHANGED
@@ -21,4 +21,36 @@
21
21
  std::cout << std::endl;
22
22
  }
23
23
  }
24
+ ```
25
+
26
+ [追記] 第二版
27
+ ```C++
28
+ #include <iostream>
29
+ #include <algorithm>
30
+
31
+ class point {
32
+ public:
33
+ int angle;
34
+ point(int a) : angle(a) {};
35
+ };
36
+
37
+ int main() {
38
+ point data[5][7] = {
39
+ { 0, 0, 0, 1, 2, 0, 0 },
40
+ { 1, 3, 2, 1, 0, 4, 3 },
41
+ { 0, 1, 1, 4, 1, 1, 4 },
42
+ { 2, 2, 4, 3, 2, 3, 2 },
43
+ { 2, 3, 4, 4, 3, 3, 4 },
44
+ };
45
+ std::sort((point*)data, (point*)data+5*7,
46
+ [](const point& a, const point& b) { return a.angle < b.angle; });
47
+
48
+ // できたかな?
49
+ for ( int row = 0; row < 5; ++row ) {
50
+ for ( int col = 0; col < 7; ++col ) {
51
+ std::cout << data[row][col].angle << ' ';
52
+ }
53
+ std::cout << std::endl;
54
+ }
55
+ }
24
56
  ```