Last character
Is challenging a crackme you, the need to fill in the first few passwords are correctly guessed, but this last password, as if hidden a bit deep. The author of the Crackme also provocative in hiding a. tar.gz file, extracted, and wrote the last character you want is in the string below. This character is the first occurrence of a character in the entire string below. (For example, the string is Abaccdeff, then the correct character is B) However, the strings given below appear to be too long and too long to be found by manpower alone. So, you need to write a program to do it. The input file volume is large, please use some fast input and output means, do not recommend the use of Cin/cout, Java is not recommended to use scanner direct read and write.
Input Description:
The first line, a positive integer T (t≤20) , represents the number of input data groups.
After the T line, each line is a string s. (The length of the 1≤s is ≤10 6 , guaranteeing that the ASCII code of the characters appearing in the string is within the range of [0x21,0x7f), that is, non-whitespace characters that can be displayed, and that there must be a solution)
Output Description:
A total of T-lines, one character c per line, representing the first character in the given string that appears only once.
Input Example:
2abaccdefftestonline
Output Example:
Bs
Code implementation:
Import Java.util.scanner;import Java.util.linkedhashset;import Java.util.iterator;public class Main{public static Voi D Main (String args[]) {Scanner sc=new Scanner (system.in); int N=sc.nextint (); for (int i=0;i<n;i++) {String s=sc.next (); int Len=s.length (); Linkedhashset<character> set=new linkedhashset<character> (); Linkedhashset<character> tmp=new linkedhashset<character> (); int m=0; for (int j=0;j<len;j++) {if (Tmp==null | |!tmp.contains (S.charat (j))) {Set.add (S.charat (j)); if (j+1! = set.size () +m) {Set.remove (S.charat (j)); Tmp.add (S.charat (j)); m+=2; }}else{m++; }} iterator<character> It=set.iterator (); Char C=it.next (); System.out.println (c); } }}
2016 360 written programming questions 1