티스토리 뷰

알고리즘/SWEA

[SWEA 1220] Magnetic

히더 2018. 8. 10. 16:05

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14hwZqABsCFAYD


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int N,result;

int arr[100][100];



int main()

{

int T; int t=1;

T = 10;

while (T--)

{

cin >> N; result = 0;

for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) cin >> arr[i][j];


for (int j = 0; j < N; j++)

{

for (int i = 0; i < N; i++)

{

if (arr[i][j] == 2) arr[i][j] = 0;

else if (arr[i][j] == 1) break;

}

for (int i = N-1; i >=0; i--)

{

if (arr[i][j] == 1) arr[i][j] = 0;

else if (arr[i][j] == 2) break;

}

}

for (int j = 0; j < N; j++)

{

int flag = 0;

for (int i = 0; i < N; i++)

{

if (arr[i][j] == 1)

{

if (flag == 0)flag = 1;

}

else if (arr[i][j] == 2)

{

if (flag == 1)

{

flag = 0; result += 1;

}

}

}

}



cout << "#" << t++ << " " << result << endl;

}


return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1222] 계산기1  (0) 2018.08.10
[SWEA 1221] GNS  (0) 2018.08.10
[SWEA 1219] 길찾기  (0) 2018.08.10
[SWEA 1218] 괄호 짝짓기  (0) 2018.08.10
[SWEA 1217] 거듭 제곱  (0) 2018.08.10
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함