Skip to content

Commit

Permalink
2021-06-26 go boj 9251+
Browse files Browse the repository at this point in the history
  • Loading branch information
wookiist committed Jun 26, 2021
1 parent 964ca6c commit 3b32d73
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions baekjoon/9251+.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"bufio"
"fmt"
"os"
)

var (
w = bufio.NewWriter(os.Stdout)
sc = bufio.NewScanner(os.Stdin)
)

var (
A, B string
D [][]int
)

func main() {
defer w.Flush()
A = scanText()
B = scanText()
D = make([][]int, len(A))
for i := range D {
D[i] = make([]int, len(B))
}
for i := 1; i < len(A); i++ {
for j := 1; j < len(B); j++ {
if A[i] == B[j] {
D[i][j] = D[i-1][j-1] + 1
} else {
D[i][j] = max(D[i-1][j], D[i][j-1])
}
}
}
res := D[len(A)-1][1]
for i := range B {
if res < D[len(A)-1][i] {
res = D[len(A)-1][i]
}
}
fmt.Fprintln(w, res)
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func scanText() string {
sc.Scan()
return " " + sc.Text()
}

0 comments on commit 3b32d73

Please sign in to comment.