http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=3057 這題就宣告n個陣列,輸入完n-1個之後下去搜尋 ps.以輸入的值-1當作索引值
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
int n = scn.nextInt(), arr[] = new int[n];
for (int i = 0; i < n - 1; i++) {
arr[scn.nextInt() - 1] = 1;
}
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
System.out.println(i + 1);
break;
}
}
}
}
/*
題目:[C_MM117-易] 少了一個數
作者:1010
時間:西元 2016 年 7 月 */
}