有必要对比下后半部分的文字,看看他们是不是兄弟
我试图找到解决这个问题的方法
这是问题链接
https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/L
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1 = in.next();
String s2 = in.next();
String s3 = in.next();
String s4 = in.next();
if (s3.length() == s4.length()) {
System.out.println("ARE Brothers");
} else {
System.out.println("NOT");
}
}
}
获取输入,用空格分割并获取结果数组中的第二项以获取姓氏。然后使用三元运算符比较两者。
Scanner s = new Scanner(System.in);
String firstLastName = s.nextLine().split(" ")[1];
String secondLastName = s.nextLine().split(" ")[1];
String result = firstLastName.equals(secondLastName) ? "ARE Brothers" : "NOT";
System.out.println(result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句