-
Notifications
You must be signed in to change notification settings - Fork 0
/
mian3.cpp
51 lines (48 loc) · 1000 Bytes
/
mian3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "mycommon.h"
using namespace std;
struct Person
{
int age;
int height;
string name;
};
using PersonField = std::variant<int Person::*, string Person::*>;
unordered_map<string_view, PersonField> person_fields = {
{"age", &Person::age},
{"height", &Person::height},
{"name", &Person::name},
};
struct n
{
int mat[2][2];
};
n mat_mul(n n1, n n2)
{
n n3;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
n3.mat[i][j] = 0;
for (int k = 0; k < 2; k++)
{
n3.mat[i][j] += n1.mat[i][k] * n2.mat[k][j];
}
}
}
return n3;
}
int main()
{
Person p1 = {20, 180, "Tom"};
for (auto &&[name, value] : person_fields)
{
visit([&](auto &&field) { cout << name << ": " << p1.*field << endl; }, value);
}
n n1 = {{{1, 0}, {0, 0}}};
// 使用矩阵乘法来计算feibinaqie数列
n n2 = {{{1, 1}, {1, 0}}};
// 第6项:
for (int i = 1; i <= 5; i++) n1 = mat_mul(n1, n2);
cout << n1.mat[0][0] << endl;
}