import java.util.Map.Entry;
import java.util.*;
/* 請實現一個函數:湊14;輸入很多個整數(1<=數值<=13),
* 任意兩個數相加等於14就可以從數組中刪除這兩個數,求剩餘數(按由小到大排列);
* 比如: 輸入數組[9,1,9,7,5,13], 輸出數組[7,9]
*/
class Main19
{
public static void main(String[] args)
{
getArr(5);
}
public static void getArr(int n){
Scanner in=new Scanner(System.in);
int[] str={1,2,3,4,5,6,7,8,9,10,11,12,13};
int[] arr=new int[n];
boolean temp=false;
for(int i=0;i<n;i++){
temp=false;//必須重至爲false;
System.out.println("輸入數字");
int m=in.nextInt();
for(int j=0;j<str.length;j++){
if(str[j]==m){
arr[i]=m;
temp=true;
break;
}
}
if(!temp){
i--;
System.out.println("請輸入正確的整數(1<=數值<=13)");
}
}
Map<Integer,Integer> map1=new HashMap<Integer,Integer>();
for(int i=0;i<n;i++){
map1.put(i,arr[i]);
}
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n;j++){
if((arr[i]+arr[j])==14){
if(map.get(j)==null&&map.get(i)==null){//判斷map中是否已存在
map.put(i,arr[i]);
map.put(j,arr[j]);
map1.remove(i);
map1.remove(j);
break;
}
}
}
}
//循環遍歷Map
Set set =map1.entrySet();
Iterator it=set.iterator();
while(it.hasNext()){
Map.Entry<Integer, Integer> entry=(Entry<Integer, Integer>)it.next();
System.out.println(entry.getValue());
}
}
}