-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add practices * edit config.ts * "+=" is difficulty to pronounce * bits is not allowed * add practice "exponentation" * fix 日本語 * delete practice "Exponantation" * add hint to divide-each-diff * line-numbers * deleted exponentation from index.md
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Divide each difficulty | ||
以下の$n \leq 7$を受け取って$n \times n$の行列$a_{i,j}=Fibonatti_{ij}$を出力するプログラムの、フィボナッチ数列の解を求める部分を別の関数`int fibonatti(int index);`に分離してみよう。 | ||
```cpp:line-numbers | ||
#include <iostream> | ||
using namespace std; | ||
int main() { | ||
int n; | ||
cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
// ここから下を関数に切り分ける | ||
// print (i*j)th of fibonatti sequence | ||
int first = 1, second = 1; | ||
for (int k = 0; k < i*j; k++) { | ||
int next = first + second; | ||
first = second; | ||
second = next; | ||
} | ||
// ここから上を関数に切り分ける | ||
cout << second << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
``` | ||
|
||
::: spoiler Hint | ||
下のコードの`// ここにフィボナッチ数列の計算を実装しよう`の部分を実装してみよう。 | ||
```cpp:line-numbers | ||
#include <iostream> | ||
using namespace std; | ||
int fibonatti(int index) { | ||
int first = 1, second = 1; | ||
// ここにフィボナッチ数列の計算を実装しよう | ||
return second; | ||
} | ||
int main() { | ||
int n; | ||
cin >> n; | ||
for (i = 0; i < n; i++) { | ||
for (j = 0; j < n; j++) { | ||
int fib_ij = fibonatti(i*j); | ||
cout << fib_ij << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
``` | ||
::: | ||
|
||
::: spoiler Answer | ||
|
||
```cpp:line-numbers | ||
#include <iostream> | ||
using namespace std; | ||
int fibonatti(int index) { | ||
int first = 1, second = 1; | ||
for (k = 0; k < index; k++) { | ||
int next = first + second; | ||
first = second; | ||
second = next; | ||
} | ||
return second; | ||
} | ||
int main() { | ||
int n; | ||
cin >> n; | ||
for (i = 0; i < n; i++) { | ||
for (j = 0; j < n; j++) { | ||
int fib_ij = fibonatti(i*j); | ||
cout << fib_ij << " "; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 練習問題 - Chapter 5 | ||
|
||
- [Divide each difficulty](divide-each-difficulty) | ||
- [Operator+=](plus-equal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Operator+= | ||
`int`型の`a`と`b`について`a`に`b`を足す操作である | ||
|
||
```cpp | ||
a += b; | ||
``` | ||
|
||
で用いる`+=`演算子と同じ働きをする関数を書こう。 | ||
|
||
::: spoiler Hint 1 | ||
`a`を参照渡しで受け取ることで、`a`の値を書き換えることができる。 | ||
::: | ||
|
||
::: spoiler Answer | ||
```cpp:line-numbers | ||
void compound_assigned_plus(int& lhs, int rhs) { | ||
lhs = lhs + rhs; | ||
return; | ||
} | ||
``` | ||
::: |