SWEA 1220 (S/W 문제해결 기본) 5일차 - Magnetic

Jmnote bot (토론 | 기여)님의 2021년 7월 31일 (토) 10:54 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

SWEA 1220 (S/W 문제해결 기본) 5일차 - Magnetic
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-7

2 C++[ | ]

3 Java[ | ]

import java.util.*;
public class Solution {
	static Scanner sc  = new Scanner(System.in);
	static StringBuilder sb = new StringBuilder();
	public static void main(String[] args) {
		for(int tc=1; tc<=10; tc++) {
			// int N = sc.nextInt();
			sc.nextInt();
			String[] columns = new String[100];
			for(int i=0; i<100; i++) columns[i] = "";
			for(int i=0; i<100; i++) {
				for(int j=0; j<100; j++) {
					columns[j] += sc.next();
				}
			}
			int result = 0;
			for(int i=0; i<100; i++) {
				String s = columns[i]
						.replace("0","")
						.replaceAll("1+","1")
						.replaceAll("2+","2")
						.replaceAll("1$","")
						.replaceAll("^2","");
				result += s.length()/2;
			}
			sb.append("#");
			sb.append(tc);
			sb.append(" ");
			sb.append(result);
			sb.append("\n");
		}
		System.out.println( sb );
		sc.close();
	}
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}