import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Iterator;
/**
*
* @author denni
*/
public class ACO201project3DSE {
public static void main(String[] args) {
char[] characters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', ' ' };
String inputList = "mam";
String dictionaryList = "a about again all an and are as at be but by " +
"can " +"do " +"down " +"first " +"for " +"from " +"good " +"have " +"he " +
"her " +"here " +"him " +"his " +"I " +"if " +"in " +"into " +"is " +"it " +"just " +
"like " +"listen " +"little " +"make " +"man " +"many " +"may " +"more " +"most " +"my "
+"near " +"no " +"not " +"now " +"of " +"on " +"one " +"only " +"or " +
"other " +"out " +"people " +"please " +"program " +"read " +"said " +"say " +"see " +"she " +
"should " +"slow " +"small " +"so " +"some " +"stop " +"than " +"that " +
"the " +"then " +"there " +"they " +"this " +"through " +"to " +"tomorrow " +
"true " +"two " +"up " +"use " +"very " +"water " +"was " +"way " +"we " +
"were " +"what " +"when " +"where " +"which " +"while " +"who " +"will " +
"with " +"would " +"write " +"yes " +"yesterday " +"you ";
//HashSet<String> dictionaryArray = new HashSet<String>();
//********************************************************************************
String[] inputCompare = inputList.split(" ");
String[] dictionaryArray = dictionaryList.split(" ");
String possibleWords = "";
String output = "";
//********************************************************************************
System.out.println("input string words separated by whitespace: "
+ inputList);
System.out.println("output string: " + Arrays.toString(inputCompare));
//********************************************************************************
for(int i = 0; i < inputCompare.length; i++)
{
//********************************************************************************
int j = 0;
while(!inputCompare[i].equals(dictionaryArray[j]))
{
j++;
if(j >= 100)
{
System.out.println(" /////////// NO MATCH FOUND ******************* ");
//********************************************************************************
String checkWord = inputCompare[i];
System.out.println("Check word is: " + checkWord);
System.out.println(freqCount(checkWord));
String[] lengthCompareInput = freqCount(checkWord).split(" ");
System.out.println(lengthCompareInput[0]);
for(int q = 0; q < dictionaryArray.length; q++)
{
String[] lengthCompareDict = freqCount(dictionaryArray[q]).split(" ");
if(lengthCompareInput[0].equals(lengthCompareDict[0]) && lengthCompareInput[1].charAt(0) == lengthCompareDict[1].charAt(0))
{
//while()
System.out.println("Match at: " + dictionaryArray[q]);
}
}
// if(lengthCompareInput[0].equals(dictionaryArray)
//System.out.println(total);
//HashSet<String> dictCheck = new HashSet<>();
// dictCheck.add(dictionaryList);
//System.out.println("Hash map contains: " + dictCheck.contains(checkWord));
//for(int k = 0; k < checkWord.length();k++)
// { //CHECK EACH LETTER OF THE INPUT WORD
//int n = 0;
// while(checkWord.charAt(k)!=characters[n])
//{
// n++;
//}
//System.out.println("Char is: " + characters[n]);
//}
//j = 0;
//i++;
}
}
//********************************************************************************
if(inputCompare[i].equals(dictionaryArray[j]))
{
//System.out.println("MATCH FOUND ******************* ");
output += inputCompare[i] + " ";
//System.out.println("MATCH FOUND: " + output);
//System.out.println("MATCH FOUND ******************* ");
}
//********************************************************************************
}
//********************************************************************************
//System.out.println("FINAL OUTPUT: " + output);
System.out.println(output);
//********************************************************************************
}
static String freqCount(String input) {
Map<Character, Integer> hashCount = new HashMap<>();
Character c;
for (int i = 0; i < input.length(); i++) {
c = input.charAt(i);
if (hashCount.get(c) != null) {
hashCount.put(c, hashCount.get(c) + 1);
} else {
hashCount.put(c, 1);
}
}
Iterator it = hashCount.entrySet().iterator();
String freq= "";
String letter = "";
String count = "";
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
letter += pairs.getKey();
freq += pairs.getValue();
it.remove();
}
count = freq + " " + letter;
return count;
}
}