import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static int square[][]; public static void main (String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input; int testno=0; StringBuilder sb=new StringBuilder(10000); while((input=br.readLine())!=null) { int dimension=Integer.parseInt(input); if(dimension==0) break; testno++; square=new int[dimension][dimension]; for (int i = 0; i < dimension; i++) { String s[]=br.readLine().split(" +"); for (int j = 0; j < dimension; j++) { square[i][j]=Integer.parseInt(s[j]); } } sb.append("Case "+testno+": "); for (int i = 0; i < dimension/2; i++) { int count=0; count +=sumsquare(i,i+1,false,dimension-i-1); count +=sumsquare(i,i,true,dimension-i); count +=sumsquare(dimension-i-1,i+1,false,dimension-i-1); count +=sumsquare(i,dimension-i-1,true,dimension-i); if(i==0) sb.append(count); else sb.append(" "+count); } if(dimension % 2!=0 && dimension/2==0) sb.append(square[(int) Math.floor(dimension / 2.0)][(int) Math.floor(dimension / 2.0)]); else if(dimension % 2!=0) sb.append(" "+square[(int) Math.floor(dimension / 2.0)][(int) Math.floor(dimension / 2.0)]); sb.append("\n"); } System.out.print(sb); } public static int sumsquare(int i,int j,boolean isrowchange,int dimension) { int count=0; if(isrowchange) { for (int k = i; k < dimension; k++) { count+=square[k][j]; } } else { for (int k = j; k < dimension; k++) { count+=square[i][k]; } } return count; } }
0 comments: