标签:Stub bin 用户输入 shm des blank 问题 value tar
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); int[] butong = new int[30]; int[] cishu = new int[30]; int n; n = cin.nextInt(); if(n <= 0) { //坑!!!!!!!!!!!!!智障吧,整数的个数还可能小于0!!!! return ; } int bt = 0, x; // HashMap<int, int> map = new HashMap<int, int>(); HashMap<Integer, Integer> map = new HashMap<>(); for(int i = 0; i < n; i++) { x = cin.nextInt(); if(map.containsKey(x)) { map.put(x, map.get(x)+1); } else { map.put(x,1); butong[bt++] = x; } } int mx = -1; int mm = -0x3f3f3f3f; for(int i = 0; i < bt; i++) { int cii = map.get(butong[i]); if( cii > mx) { mx = cii; mm = butong[i]; } if(cii == mx) { if(mm > butong[i]) { mm = butong[i]; } } } System.out.println(mm); } }
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); if(n <= 0) { //坑!!!!!!!!!!!!!智障吧,整数的个数还可能小于0!!!! return ; } long x, cnt = 0, min = -0x3f3f3f3f; long bf = -0x3f3f3f3f; long dangci = 0; for(int i = 0; i < n; i++) { x = cin.nextLong(); if(x == bf) { dangci++; } else { if(cnt < dangci) { cnt = dangci; min = bf; } else if(cnt == dangci && min > bf) { cnt = dangci; min = bf; } bf = x; dangci = 1; } } if(cnt < dangci) { cnt = dangci; min = bf; } else if(cnt == dangci && min > bf) { cnt = dangci; min = bf; } System.out.println(min); } }
标签:Stub bin 用户输入 shm des blank 问题 value tar
原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/10421600.html