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);
}
}