[SWEA]농작물 수확하기

Posted by kyoungIn on March 12, 2019

농작물 수확하기

링크

풀이

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

using namespace  std;

int main(){
    int t,idx; cin >> t;
    
    for(int idx=1;idx<=t;idx++){
        int i,j,s,result=0;
        scanf("%d",&s);
        int cnt=1,start=s/2;
        for(i=0;i<s;i++){
            int mm=start,c=1;
            for(j=0;j<s;j++){
                int temp;
                scanf("%1d",&temp);
                if(j==mm && c<=cnt){
                    result+=temp;
                    c++;
                    mm++;
                }
            }
            if(i>=s/2) {cnt-=2; start+=1; }
            else       {cnt+=2 ; start-=1; }
        }
        cout <<'#'<<idx<<' '<<result <<'\n';
    }
}