1 import java.util.Scanner; 2 public class Main{ 3 public static void main(String[] args){ 4 Scanner myScanner = new Scanner(System.in); 5 int n = myScanner.nextInt(); 6 int[] scores = new int[n]; 7 for(int i = 0;i<n;i++){ 8 scores[i] = myScanner.nextInt(); 9 } 10 11 int minScore = scores[0]; 12 int minCount = 1; 13 int maxScore = scores[0]; 14 int maxCount = 1; 15 for(int i = 1;i<n;i++){ 16 if(scores[i] < minScore){ 17 minScore = scores[i]; 18 minCount = 1; 19 }else if(scores[i] == minScore){ 20 21 minCount++; 22 } 23 24 if(scores[i] > maxScore){ 25 maxScore = scores[i]; 26 maxCount = 1; 27 }else if(scores[i] == maxScore){ 28 maxCount++; 29 } 30 } 31 System.out.println(minScore +" " +minCount); 32 System.out.println(maxScore +" " +maxCount); 33 } 34 }
标签:第一行,int,能力,学生,maxScore,参赛 From: https://www.cnblogs.com/wzyxslx/p/18450592