ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2740
// ํ๋ ฌ์ ๊ฑฐ๋ญ์ ๊ณฑ์ ๊ณ์ฐํ๊ธฐ ์ ์ ๋จผ์ ํ์ด์ผ ํ ๋ฌธ์
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, m, k int
fmt.Fscanln(reader, &n, &m)
var a = make([][]int, n)
for i := 0; i < n; i++ {
a[i] = make([]int, m)
for j := 0; j < m; j++ {
fmt.Fscanf(reader, "%d ", &a[i][j])
}
}
fmt.Fscanln(reader, &m, &k)
var b = make([][]int, m)
for i := 0; i < m; i++ {
b[i] = make([]int, k)
for j := 0; j < k; j++ {
fmt.Fscanf(reader, "%d ", &b[i][j])
}
}
var result = make([][]int, n)
for i := 0; i < n; i++ {
result[i] = make([]int, k)
for j := 0; j < k; j++ {
for l := 0; l < m; l++ {
result[i][j] += a[i][l] * b[l][j]
}
}
}
for i := 0; i < n; i++ {
for j := 0; j < k; j++ {
fmt.Fprintf(writer, "%d ", result[i][j])
}
fmt.Fprintln(writer, "")
}
}
๐จ Python3
# https://www.acmicpc.net/problem/2740
# ํ๋ ฌ์ ๊ฑฐ๋ญ์ ๊ณฑ์ ๊ณ์ฐํ๊ธฐ ์ ์ ๋จผ์ ํ์ด์ผ ํ ๋ฌธ์
import sys
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
a = []
for i in range(n):
a.append(list(map(int, sys.stdin.readline().split())))
m, k = list(map(int, sys.stdin.readline().split()))
b = []
for i in range(m):
b.append(list(map(int, sys.stdin.readline().split())))
result = [[0 for i in range(k)] for j in range(n)]
for i in range(n):
for j in range(k):
for l in range(m):
result[i][j] += a[i][l] * b[l][j]
for i in range(n):
for j in range(k):
print("{} ".format(result[i][j]), end='')
print()
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2178๋ฒ / ๋ฏธ๋ก ํ์ [Go][Python3] (0) | 2021.01.03 |
---|---|
BOJ / 9372๋ฒ / ์๊ทผ์ด์ ์ฌํ [Go][Python3] (0) | 2021.01.02 |
BOJ / 1629๋ฒ / ๊ณฑ์ [Go][Python3] (0) | 2020.12.31 |
BOJ / 1780๋ฒ / ์ข ์ด์ ๊ฐ์ [Go][Python3] (0) | 2020.12.30 |
BOJ / 1992๋ฒ / ์ฟผ๋ํธ๋ฆฌ [Go][Python3] (0) | 2020.12.29 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- BOJ
- Golang
- ํ
- ๋งฅ๋ถ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถํ๋ก
- ๋ฐ๋
- python3
- MongoDB
- dp
- dfs
- ballet
- Algorithm
- ์๋ฐ
- ์๊ณ ๋ฆฌ์ฆ
- ๋ชฝ๊ณ ๋๋น
- BFS
- ํ๋ก์ด๋์์ฌ
- ์ด๋ถํ์
- go
- ํด์๋งต
- java
- ๋ฐฑ์ค
- ์คํ
- ์๊ฐ๊ต์ฒด
- baekjoon
- AWS
- Macbook pro 2012 mid 13
- Total
- Today
- Yesterday