参考代码:
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String in = scanner.nextLine(); String s = new StringBuilder(in).reverse().toString(); Pattern pattern = Pattern.compile("[^\\s,]+"); Matcher matcher = pattern.matcher(s); String max = ""; String min = null; int minlen = Integer.MAX_VALUE; while(matcher.find()) { String word = matcher.group(); if(minlen >= word.length() && word.equals("\"") == false && word.equals(".") == false) { minlen = word.length(); min = word; } if(max.length() <= word.length()) max = word; } System.out.print(new StringBuilder(max).reverse() + "\n" + new StringBuilder(min).reverse()); } }
0.0分
4 人评分