A Contesting Decision
題目:對於程式設計競賽的裁判來說,用軟體使得評測過程自動化很有幫助。你是致力於將競賽管理軟體發展得更好的團隊中之一員。基於模組化的設計原則,你所開發的模組之功能是為參加程式競賽的隊伍計算分數並確定優勝者。列出參賽隊伍在比賽中的情況,請確定比賽的優勝者。記分規則為每一支參賽隊的記分由兩部分組成:第一部分是被解出的題數,第二部分是加罰時間,表示解題總共耗費時間和試題沒有被解出前錯誤的提交所另加罰的時間。對於每個被正確解出的問題,加罰時間等於該問題被解出的時間加上每次錯誤提交的20分鐘加罰時間。在問題沒有被解出前不加罰時間。優勝隊是解出最多問題的隊伍。如果兩隊在解題數上打成平手,那麼加罰時間少的隊伍就是優勝隊。
輸入:程式評判的程式設計競賽有點題。程式要確保在計算加罰時間後,不會導致隊與隊之間不分勝負的情況。第1行為參賽隊數n,第2~n+1行為每個隊的參賽情況,每行格式為:
< Name > < p1Sub > < p1Time > < p2Sub > < p2Time > … < p4Sub > < p4Time >
輸出:輸出一行。列出優勝隊的隊名,解出題目的數量以及加罰時間。
import java.util.Scanner;
public class AContestingDecision {
static String name[]; //所有隊的隊名
static int q[][], a[][]; //所有隊的解題數目與各題解題時間
static String wname; //冠軍隊隊名
static int sol, pt; //冠軍隊解題數目與加罰時間
public static void main(String[] args) {
Scanner scanIn = new Scanner(System.in); //輸入參賽組數
int n = scanIn.nextInt();
name = new String[n]; q = new int[n][4]; a = new int[n][4];
int i = 0;
while(i < n) {
scanIn = new Scanner(System.in);
name[i] = scanIn.next(); //取得輸入組的隊名與解題資料
q[i][0] = scanIn.nextInt();
a[i][0] = scanIn.nextInt();
q[i][1] = scanIn.nextInt();
a[i][1] = scanIn.nextInt();
q[i][2] = scanIn.nextInt();
a[i][2] = scanIn.nextInt();
q[i][3] = scanIn.nextInt();
a[i][3] = scanIn.nextInt();
if(i == 0){ //假設第一隊為冠軍隊
wname = name[i];
for(int j = 0; j < q[i].length; j++){
if(a[i][j] > 0)
{
++sol;
pt += (q[i][j] - 1) * 20 + a[i][j];
}
}
System.out.printf("%s %d %d", wname, sol, pt);
} else {
int tempSol = 0, tempPt = 0;
String tempWname = name[i];
for(int j = 0; j < q[i].length; j++){
if(a[i][j] > 0)
{
++tempSol;
tempPt += (q[i][j] - 1) * 20 + a[i][j];
}
}
//計算後如解題數最多的取代為冠軍隊,如相等解題數再比較加罰時間少的為冠軍隊
if( tempSol > sol || (tempSol == sol && pt > tempPt)){
wname = name[i];
sol = tempSol;
pt = tempPt;
}
System.out.printf("%s %d %d", tempWname, tempSol, tempPt);
}
i++;
}
System.out.printf("%s %d %d", wname, sol, pt); //輸出冠軍隊資料
}
}
鏈結到這頁!