- //由最內至外 依c的退步 斜線求出各行各列
- //由於偶數最中間是4個數字 故須特別 行,列+1再把邊界延升
- import java.util.*;
- class main{
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int size , C=1;
- while((size=sc.nextInt())!=0){
- int[][] Matrix = new int[size][size];
- int i , j ;
- for( i=0;i<size;i++)
- for( j=0;j<size;j++)
- Matrix[i][j]=sc.nextInt();
- //-----------
- int count = (size-1)/2;
- int[] st = new int[count+1];
- int bounds = count;
- if(size%2==0) bounds++;
- for(int c=0;c<=count;c++){
- for( i=count-c;i<=bounds+c;i++){
- for( j=count-c;j<=bounds+c;j++){
- st[c]+=Matrix[i][j];
- Matrix[i][j]=0;
- }
- }
- }
- //----------
- for(int v=count;v>=0;v--)
- System.out.print((v==count?"Case "+(C++)+": ":" ")+st[v]);
- System.out.println();
- }
- }
- }
2017年9月12日 星期二
UVA 10279:Minesweeper
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。