我正在尝试学习 java,我在旧的 UIL 练习测试中遇到了这段代码,我无法弄清楚这部分代码在做什么。
d[i][j] = eval(d[i-1][j]+1
[i][j-1]+1, d[i-1][j-1] + cost); /* the commas confuse me, I don't know what to add to cost */
如果有帮助,这是整个代码
private static int eval(int a, int b, int c) {
int m;
m = a;
if (b < m)
m = b;
if (c < m)
m = c;
return m;
}
public static int comp(String s, String t) {
int d[][];
int n, m, i, j;
char si, tj, cost;
n = s.length();
m = t.length();
if (n == 0) {
return m;
}
if (m == 0) {
return n;
}
d = < * 1 >;
for (i = 0; i <= n; i++) {
d[i][0] = i;
}
for (j = 0; j <= m; j++) {
d[0][j] = j;
}
for (i = 1; i <= n; i++) {
si = s.charAt(i - 1);
for (j = 1; j <= m; j++) {
tj = t.charAt(j - 1);
if (si == tj) {
cost = 0;
} else {
cost = 1;
}
d[i][j] = eval(d[i - 1][j] + 1,
d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
}
}
return d[n][m];
}