Describe |
Title Description |
Knowledge points |
Find |
Run time limit |
10M |
Memory limit |
128 |
Input |
First enter the number of words in the dictionary, and then enter n words as dictionary words. Enter a word to find the number of sibling words in the dictionary Re-enter the number n |
Output |
The number of sibling words that the output finds, based on the input Outputs a specified nth sibling word |
Sample input |
3 ABC BCA CAB ABC 1 |
Sample output |
2 BCA |
Package Com.oj5;import Java.util.iterator;import Java.util.map;import java.util.scanner;import java.util.Set;import Java.util.treemap;import Java.util.treeset;public class Oj {public static void main (string[] args) {Scanner in = new Scann ER (system.in); int num = In.nextint (); In.nextline (); string[] data = new String[num];for (int i = 0;i < num; i++) data[i] = In.nextline (); String input = In.nextline (); int inputnum = In.nextint (); int count = 0; set<string> set = new Treeset<string> (), for (int i = 0;i < num; i++) if (Isbrother (data[i],input)) {count++; Set.add (Data[i]);} System.out.println (count);iterator<string> iter = Set.iterator (); int k = 0;while (Iter.hasnext ()) {k++; String value = Iter.next (); if (k==inputnum) System.out.println (value);}} private static Boolean Isbrother (string src, string input) {//system.out.println ("src:" +src+ "" +input), if (Src.equals ( Input)) return False;else if (Src.length ()!=input.length ()) {return false;} else{map<character,integer> mapsrc = new TreEmap<character,integer> (); map<character,integer> mapinput = new treemap<character,integer> (); for (int i = 0;i < Src.length (); i++) if (Mapsrc.containskey (Src.charat (i))) {Mapsrc.put (Src.charat (i), 1+mapsrc.get (Src.charat (i)));} Else{mapsrc.put (Src.charat (i), 1);} for (int i = 0;i < Input.length (); i++) if (Mapinput.containskey (Input.charat (i))) {Mapinput.put (Input.charat (i), 1+ Mapinput.get (Input.charat (i))); Else{mapinput.put (Input.charat (i), 1);} System.out.println ("Hi1:" +SRC); for (Map.entry<character, integer> srcEntry:mapSrc.entrySet ()) {Character Key = Srcentry.getkey (); int value2;try{value2 = mapinput.get (key);} catch (Exception e) {return false;} if (Value2!=srcentry.getvalue ()) return false;} System.out.println ("Hi2:" +SRC); for (Map.entry<character, integer> inputEntry:mapInput.entrySet ()) { Character Key2 = Inputentry.getkey (); int value;try{value = Mapsrc.get (Key2);} catch (Exception e) {return false;} System.out.println (key2+ "" +value); if (Value!=inputentry.getvAlue ()) return false;} System.out.println ("Hi3:" +SRC); return true;}}}
find brother Words