๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[SW Expert Academy] - (D3)4751. ๋‹ค์†”์ด์˜ ๋‹ค์ด์•„๋ชฌ๋“œ ์žฅ์‹

by ์ฃผ๋ฐœ2 2020. 5. 25.
๋ฐ˜์‘ํ˜•

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWSNw5jKzwMDFAUr

 

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);

		// ์ฒซ๋ฒˆ์งธ, ๋‹ค์„ฏ๋ฒˆ์งธ ํ–‰
		String str1 = "..#..";
		String str2 = ".#..";

		// ๋‘๋ฒˆ์งธ, ๋„ค๋ฒˆ์งธ ํ–‰
		String str3 = ".#.#.";
		String str4 = "#.#.";

		int T = scan.nextInt();
		for(int i=0; i<T; i++) {
			String str = scan.next();

			/* ์ฒซ๋ฒˆ์งธ ํ–‰ */
			for(int k=0; k<str.length(); k++) {
				if(k == 0) System.out.print(str1);
				else System.out.print(str2);
			}
			System.out.println();

			/* ๋‘๋ฒˆ์งธ ํ–‰ */
			for(int k=0; k<str.length(); k++) {
				if(k == 0) System.out.print(str3);
				else System.out.print(str4);
			}
			System.out.println();

			/* ์„ธ๋ฒˆ์งธ ํ–‰ */
			for(int k=0; k<str.length(); k++) {
				if(k == 0) System.out.print("#." + str.charAt(k) + ".#");
				else System.out.print("." + str.charAt(k) + ".#");
			}
			System.out.println();

			/* ๋„ค๋ฒˆ์งธ ํ–‰ */
			for(int k=0; k<str.length(); k++) {
				if(k == 0) System.out.print(str3);
				else System.out.print(str4);
			}
			System.out.println();
			
			/* ๋‹ค์„ฏ๋ฒˆ์งธ ํ–‰ */
			for(int k=0; k<str.length(); k++) {
				if(k == 0) System.out.print(str1);
				else System.out.print(str2);
			}
			System.out.println();
		}

		scan.close();
	}

}

ํ’€์ด

๋ฌธ์ œ ์ถœ๋ ฅ์ด 5ํ–‰์ด๋ผ์„œ ๊ฐ ํ–‰์˜ ๊ทœ์น™์—๋”ฐ๋ผ ๊ฐ๊ฐ ์ถœ๋ ฅ์„ ํ–ˆ๋‹ค.

์ฒซ๋ฒˆ์งธ, ๋‹ค์„ฏ๋ฒˆ์งธ ํ–‰์˜ ๊ฒฝ์šฐ ์ฒ˜์Œ์€ "..#.." ๋กœ ์‹œ์ž‘ํ•˜๊ณ , ๊ทธ ์ดํ›„๋ก  ".#.." ๋กœ ์‹œ์ž‘ํ•œ๋‹ค.

๋‘๋ฒˆ์งธ, ๋„ค๋ฒˆ์งธ ํ–‰์˜ ๊ฒฝ์šฐ ์ฒ˜์Œ์€ ".#.#." ๋กœ ์‹œ์ž‘ํ•˜๊ณ , ๊ทธ ์ดํ›„๋ก  "#.#." ๋กœ ์‹œ์ž‘ํ•œ๋‹ค.

์„ธ๋ฒˆ์งธ ํ–‰์˜ ๊ฒฝ์šฐ ์ฒ˜์Œ์€ "#.๋ฌธ์ž์—ด.#" ๋กœ ์‹œ์ž‘ํ•˜๊ณ , ๊ทธ ์ดํ›„๋ก  ".๋ฌธ์ž์—ด.#" ๋กœ ์‹œ์ž‘ํ•œ๋‹ค.

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€