# 面試
https://github.com/aspspspsp/HoungYangInterview
## WordCount
```clike=
public class StringTest {
public static void main(String[] args) {
var sma = new StringManipulationAlgorithms();
sma.sssss();
}
}
public class StringManipulationAlgorithms {
private class entry{
private String str;
private Integer count;
public entry(String str, Integer count) {
this.str = str;
this.count = count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return str + "(" + count + ")";
}
}
public void sssss() {
String paragraph = "Wikileaks began on Sunday November 28th publishing 251,287 leaked United States embassy cables, the largest set of confidential documents ever to be released into the public domain. The documents will give people around the world an unprecedented insight into US Government foreign activities."
+ "The cables, which date from 1966 up until the end of February this year, contain confidential communications between 274 embassies in countries throughout the world and the State Department in Washington DC. 15,652 of the cables are classified Secret."
+ "The embassy cables will be released in stages over the next few months. The subject matter of these cables is of such importance, and the geographical spread so broad, that to do otherwise would not do this material justice.";
var a = paragraph.toLowerCase().replaceAll("[^a-z]", " ").split(" ");
Map<String, entry> map = new HashMap<String, entry>();
for(var aa : a) {
if(aa.isEmpty())
continue;
if(!map.containsKey(aa))
map.put(aa, new entry(aa, 1));
else {
Integer aaa = map.get(aa).count;
map.get(aa).setCount(aaa + 1);
}
}
List<entry> list = new ArrayList<entry>();
for(var entr : map.keySet())
list.add(map.get(entr));
var b = insertionSort(list);
for(var ob : b)
System.out.println(ob);
}
private List<entry> insertionSort(List<entry> array) {
for(int i = 1 ; i < array.size() ; i ++) {
int temp = array.get(i).count;
int j = i - 1;
while(j >= 0 && temp >= array.get(j).count) {
array.get(j + 1).count = array.get(j).count;
j --;
}
array.get(j + 1).count = temp;
}
return array;
}
}
```