import java.util.Scanner;
public class Test1 {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println("請輸入學生的人數:");
int renshu=in.nextInt();
System.out.println("請輸入課程數目:");
int courseNum=in.nextInt();
String[] name=new String[renshu];
String[] course=new String[courseNum];
int[][] number=new int[renshu] [courseNum];
int[] sum=new int[renshu];
int avg[]=new int[renshu];
String[] str=new String[renshu];
for(int i=0;i<course.length;i++)
{
System.out.println("請定義第"+(i+1)+"門課程的名字");
course[i]=in.next();
}
for(int i=0;i<renshu;i++)
{
int S=0;
System.out.println("請輸入學生的姓名:");
name[i]=in.next();
String str11="";
for(int j=0;j<courseNum;j++)
{
System.out.println("請輸入學生"+name[i]+course[j]+"的成績");
number[i][j]=in.nextInt();
S+=number[i][j];
str11+=number[i][j]+"\t";
}
sum[i]=S;
avg[i]=S/courseNum;
str[i]=name[i]+"\t"+str11+sum[i]+"\t"+avg[i];
}
for(int i=0;i<sum.length-1;i++)
{
for(int j=0;j<sum.length-1;j++)
{
if(sum[j]<sum[j+1])
{
int t1=sum[j]; String t2=str[j];
sum[j]=sum[j+1]; str[j]=str[j+1];
sum[j+1]=t1; str[j+1]=t2;
}
}
}
System.out.print("學生");
for(int i=0;i<course.length;i++)
{
System.out.print("\t"+course[i]);
}
System.out.print("\t"+"總分"+"\t"+"平均分"+"\t"+"排行榜");
System.out.println();
for(int i=0;i<renshu;i++)
{
System.out.println(str[i]+"\t"+"第"+(i+1)+"名");
}
}
}