Created
April 13, 2018 06:29
-
-
Save jacknie84/6746c14bdb47a06a1016f93639ce4bef to your computer and use it in GitHub Desktop.
카카오신입공채 코딩테스트 1차(JAVA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jacknie.doodle.kakao; | |
import java.util.Arrays; | |
public class KakaoTest1 { | |
public static void main(String[] args) { | |
String[] r1 = decryptMap(5, new int[] {9, 20, 28, 18, 11}, new int[] {30, 1, 21, 17, 28}); | |
String[] r2 = decryptMap(6, new int[] {46, 33, 33, 22, 31, 50}, new int[] {27, 56, 19, 14, 14, 10}); | |
System.out.println(Arrays.toString(r1)); | |
System.out.println(Arrays.toString(r2)); | |
} | |
static String[] decryptMap(int n, int[] arr1, int[] arr2) { | |
String[] map = new String[n]; | |
for (int i = 0; i < n; i++) { | |
int row = arr1[i] | arr2[i]; | |
map[i] = toMapRowString(n, row); | |
} | |
return map; | |
} | |
private static String toMapRowString(int n, int row) { | |
StringBuilder builder = new StringBuilder("\""); | |
for (int i = n - 1; i >= 0; i--) { | |
int mask = (int) Math.pow(2, i); | |
if (((row & mask) >> i) == 1) { | |
builder.append("#"); | |
} | |
else { | |
builder.append(" "); | |
} | |
} | |
return builder.append("\"").toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment