给定两个数字,从它们的最低位开始进行比较,该位数字的值严格小于另一方的,则该位的数字会掉落。最终两个
数字的值会变为多少。
因为是需要每一位都进行比较,所以使用字符串处理会更方便。
public static void solve() throws IOException {
char[] a = next().toCharArray();
char[] b = next().toCharArray();
boolean[] vis1 = new boolean[a.length];
boolean[] vis2 = new boolean[b.length];
for (int i = a.length - 1, j = b.length - 1; i >= 0 && j >= 0; i--, j--) {
if (a[i] > b[j]) vis2[j] = true;
else if (a[i] < b[j]) vis1[i] = true;
}
boolean ok = true;
for (int i = 0; i < a.length; i++) ok = ok & vis1[i];
if (ok) pw.println("YODA");
else pw.println(getNum(a, vis1));
ok = true;
for (int i = 0; i < b.length; i++) ok = ok & vis2[i];
if (ok) pw.println("YODA");
else pw.println(getNum(b, vis2));
}
public static int getNum(char[] c, boolean[] vis) {
int re = 0;
for (int i = 0, len = c.length; i < len; i++)
if (!vis[i]) re = re * 10 + (c[i] - '0');
return re;
}