結果

問題 No.225 文字列変更(medium)
ユーザー fmhrfmhr
提出日時 2015-06-12 23:00:30
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 877 bytes
コンパイル時間 10,549 ms
コンパイル使用メモリ 229,568 KB
実行使用メモリ 12,064 KB
最終ジャッジ日時 2024-04-19 02:23:02
合計ジャッジ時間 11,363 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, m int
	var S, T string
	fmt.Scan(&n, &m, &S, &T)
	s:= strings.Split(S,"")
	t:= strings.Split(T,"")
	fmt.Println(lesvenshteinDistance(s, t))
}

func lesvenshteinDistance(str1 []string, str2 []string)int{
	d := makeDoubleSliceInt(len(str1)+1, len(str2)+1)
	for i1 :=0; i1<=len(str1);i1++{
		d[i1][0]=i1
	}
	for i2:=0; i2<=len(str2);i2++{
		d[0][i2] = i2
	}
	var cost int
	for i:=1;i<=len(str1);i++{
		for j:=1;j<=len(str2);j++{
			if str1[i]==str2[j]{
				cost=0
			}else{
				cost=1
			}
			d[i][j]=min(d[i-1][j]+1, min(d[i][j-1]+1, d[i-1][j-1]+cost))
		}
	}
	//fmt.Println(d)
	return d[len(str1)-1][len(str2)-1]
}

func makeDoubleSliceInt(y, x int) [][]int {
	ss := make([][]int, y)
	for i := range ss {
		ss[i] = make([]int, x)
	}
	return ss
}

func min(a, b int) int {
	if a < b {
		a, b = b, a
	}
	return b
}
0