http://lx.lanqiao.cn/PRoblem.page?gpid=T111
按照題意,是應該用數組來做的,后面用集合的方式就不能通過官方測試系統。(有點醉~~~)
//通過import java.util.Scanner;public class Main { public static void main(String[] args){ int[] a = new int[1001]; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int max = 0; int t = 0; for (int i=0;i<n;i++){ a[i] = sc.nextInt(); if (i==0){ max = a[i]; t = i; }else if (i>0){ if (max <a[i]){ max = a[i]; t = i; } } } System.out.println(max +" " +t); }}//不能通過import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class Main { public static void main(String[] args){ Map<Integer, Integer> map = new HashMap<Integer, Integer>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int max = 0; int t = 0; int key; for (key=0;key<n;key++){ int value = sc.nextInt(); map.put(key, value); if (key==0){ max = map.get(key); t=key; }else if(key>0){ if (max < map.get(key)){ max = map.get(key); t = key; } System.out.println("t="+t + "max="+max); } } System.out.println(max + " " +t); }}新聞熱點
疑難解答