λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Algorithm

[SW Expert Academy] - (D3)5356. μ˜μ„μ΄μ˜ μ„Έλ‘œλ‘œ λ§ν•΄μš”

by 주발2 2020. 6. 14.
λ°˜μ‘ν˜•

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWVWgkP6sQ0DFAUO&categoryId=AWVWgkP6sQ0DFAUO&categoryType=CODE

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

 

 

 

 

μ½”λ“œ

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int t = scan.nextInt();
		

		for(int tc=1; tc<=t; tc++) {
			String result = "";	// κ²°κ³Ό κ°’
			char[][] cArr = new char[5][15];

			for(int i=0; i<cArr.length; i++) {
				String str = scan.next();
//				cArr[i] = str.toCharArray();
				for(int j=0; j<str.length(); j++) {
					cArr[i][j] = str.charAt(j);
				}
			}

			for(int i=0; i<15; i++) {
				for(int j=0; j<5; j++) {
					if(cArr[j][i] != 0) {
						result += cArr[j][i];
					}
				}
			}
			System.out.println("#" + tc + " " + result);
		}

		scan.close();
	}

}

풀이

λ¬Έμ œμ—μ„œ λ‹¨μ–΄μ˜ κ°―μˆ˜λŠ” 5개이고, 각 λ‹¨μ–΄μ˜ κΈΈμ΄λŠ” 1~15이닀. 

λ”°λΌμ„œ char 2차원 배열을 char[5][15] 둜 μ„€μ •ν–ˆλ‹€.

μ„Έλ‘œλ‘œ 값을 읽고, λ‹¨μ–΄λ§ˆλ‹€ 길이가 λ‹€λ₯Ό 수 μžˆμœΌλ―€λ‘œ char λ°°μ—΄μ˜ 값이 0이 μ•„λ‹κ²½μš°, 문자λ₯Ό μΆ”κ°€ν•΄μ€€λ‹€.

μ„Έλ‘œλ‘œ μ½μœΌλ―€λ‘œ 값은 cArr[j][i] 이 λœλ‹€.

 

 

λ°˜μ‘ν˜•

λŒ“κΈ€