Skip to content

Commit

Permalink
Rewrite 0003.md 💀 (#129)
Browse files Browse the repository at this point in the history
* fix: rewrite 0003.md

* fix: 0003 typo
  • Loading branch information
MasterIceZ authored Jun 22, 2023
1 parent 7eff37c commit a6c367d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions md/0003.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
ปัญหาที่ให้มาในข้อนี้คือการบวกเมทริกซ์ขนาด m x n ที่ให้มาในข้อมูลนำเข้า $A$ และ $B$ จริงๆแล้วเราสามารถแทนได้ด้วย 2d array ดังนั้นเราสามารถที่จะไล่ for loop สองชั้นโดยในแต่ละขั้นตอนเราจะมีคู่อันดับ $(i, j)$ บ่งบอกถึงหนึ่งช่องของเมทริกซ์ ดังนั้นเราสามารถจะ print $A[i][j] + B[i][j]$ ออกมาได้เลย โค้ดของโจทย์ข้อนี้เป็นดังต่อไปนี้
ปัญหาที่ให้มาในข้อนี้คือการบวกเมทริกซ์ขนาด $m \times n$ ที่ให้มาในข้อมูลนำเข้า $A$ และ $B$ จริง ๆ แล้วเราสามารถแทนได้ด้วย 2D array ดังนั้นเราสามารถที่จะไล่ for loop สองชั้นโดยในแต่ละขั้นตอนเราจะมีคู่อันดับ $(i, j)$ บ่งบอกถึงหนึ่งช่องของเมทริกซ์ ดังนั้นเราสามารถจะ แสดงค่า $A[i][j] + B[i][j]$ ออกมาได้เลย โค้ดของโจทย์ข้อนี้เป็นดังต่อไปนี้

```cpp
#include <cstdio>
using namespace std;

int m, n, A[100][100], B[100][100];
int a[110][110], b[110][110];
int main() {
int m, n;
scanf("%d %d", &m, &n);
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
scanf("%d", &A[i][j]);
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &a[i][j]);
}
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
scanf("%d", &B[i][j]);
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &b[i][j]);
}
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
printf("%d ", A[i][j] + B[i][j]);
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
printf("%d ", a[i][j] + b[i][j]);
}
printf("\n");
}
return 0;
}
```

0 comments on commit a6c367d

Please sign in to comment.