題目連結
題意:
一間公司決定裁員,對象是最高薪與最低薪者
每組測資給三個員工的薪水,求沒被裁員者的薪水
解法:
找中位數即可
每組只有三個數字,資料範圍也很小(1000~10000)
可以判斷中間值的做法都可以
程式(Java):
題意:
一間公司決定裁員,對象是最高薪與最低薪者
每組測資給三個員工的薪水,求沒被裁員者的薪水
解法:
找中位數即可
每組只有三個數字,資料範圍也很小(1000~10000)
可以判斷中間值的做法都可以
程式(Java):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
int T = sc.nextInt(); | |
int arr[] = new int[3]; | |
for (int i = 1; i <= T; i++) { | |
arr[0] = sc.nextInt(); | |
arr[1] = sc.nextInt(); | |
arr[2] = sc.nextInt(); | |
Arrays.sort(arr); | |
System.out.println("Case " + i + ": " + arr[1]); | |
} | |
} | |
} |
留言
張貼留言