题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int num = fzhinput.nextInt(); ArrayList<String> zd= new ArrayList<>(); ArrayList<String> brothers = new ArrayList<>(); for(int i =0;i<num;i++){ zd.add(fzhinput.next()); } String cxdx = fzhinput.next(); int index = fzhinput.nextInt(); int count; for(String da : zd){ if(da.length()!=cxdx.length()||da.equals(cxdx)){ } else{ char word[] = da.toCharArray(); char mbword[] = cxdx.toCharArray(); Arrays.sort(word); Arrays.sort(mbword); boolean result = Arrays.equals(word,mbword); if(result){ brothers.add(da); } } } Collections.sort(brothers); System.out.println(brothers.size()); if (index <= brothers.size()) { System.out.println(brothers.get(index - 1)); } } }