직사각형 형태의 그림 파일이 있고, 이 그림 파일은 1 × 1 크기의 정사각형 크기의 픽셀로 이루어져 있습니다.
이 그림 파일을 나타낸 문자열 배열 picture
과 정수 k
가 매개변수로 주어질 때, 이 그림 파일을 가로 세로로 k
배 늘린 그림 파일을 나타내도록 문자열 배열을 return 하는 solution 함수를 작성해 주세요.
picture
의 길이 ≤ 20picture
의 원소의 길이 ≤ 20picture
의 원소의 길이는 같습니다.picture
의 원소는 '.'과 'x'로 이루어져 있습니다.k
≤ 10picture | k | result |
---|---|---|
[".xx...xx.", "x..x.x..x", "x...x...x", ".x.....x.", "..x...x..", "...x.x...", "....x...."] | 2 | ["..xxxx......xxxx..", "..xxxx......xxxx..", "xx....xx..xx....xx", "xx....xx..xx....xx", "xx......xx......xx", "xx......xx......xx", "..xx..........xx..", "..xx..........xx..", "....xx......xx....", "....xx......xx....", "......xx..xx......", "......xx..xx......", "........xx........", "........xx........"] |
["x.x", ".x.", "x.x"] | 3 | ["xxx...xxx", "xxx...xxx", "xxx...xxx", "...xxx...", "...xxx...", "...xxx...", "xxx...xxx", "xxx...xxx", "xxx...xxx"] |
입출력 예 #1
picture
는 다음과 같습니다..xx...xx.
x..x.x..x
x...x...x
.x.....x.
..x...x..
...x.x...
....x....
이를 가로 세로로 k배, 즉 2배 확대하면 그림 파일은 다음과 같습니다...xxxx......xxxx..
..xxxx......xxxx..
xx....xx..xx....xx
xx....xx..xx....xx
xx......xx......xx
xx......xx......xx
..xx..........xx..
..xx..........xx..
....xx......xx....
....xx......xx....
......xx..xx......
......xx..xx......
........xx........
........xx........
따라서 ["..xxxx......xxxx..", "..xxxx......xxxx..", "xx....xx..xx....xx", "xx....xx..xx....xx", "xx......xx......xx", "xx......xx......xx", "..xx..........xx..", "..xx..........xx..", "....xx......xx....", "....xx......xx....", "......xx..xx......", "......xx..xx......", "........xx........", "........xx........"]를 return 합니다.입출력 예 #2
picture
는 다음과 같습니다.x.x
.x.
x.x
이를 가로 세로로 k배, 즉 3배 확대하면 그림 파일은 다음과 같습니다.xxx...xxx
xxx...xxx
xxx...xxx
...xxx...
...xxx...
...xxx...
xxx...xxx
xxx...xxx
xxx...xxx
따라서 ["xxx...xxx", "xxx...xxx", "xxx...xxx", "...xxx...", "...xxx...", "...xxx...", "xxx...xxx", "xxx...xxx", "xxx...xxx"]를 return 합니다.import java.util.*;
class Solution {
public String[] solution(String[] picture, int k) {
List<String> strArray = new ArrayList<>();
for (String str : picture) {
String temp = "";
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
for (int j = 0; j < k; j++) {
temp += String.valueOf(ch[i]);
}
}
strArray.add(temp);
}
List<String> answer = new ArrayList<>();
for (String str : strArray) {
for (int i = 0; i < k; i++) {
answer.add(str);
}
}
return answer.toArray(new String[answer.size()]);
}
}