Aracade Intro #15 AddBorder, Codefights, CodeSignal
Q.
Given a rectangular matrix of characters, add a border of asterisks(*) to it.
주어진 글자 매트릭스에다가, 외곽에 * 테두리를 추가하라
e.g.
Input ->
picture = ["abc",
"ded"]
Output ->
addBorder(picture) = ["*****",
"*abc*",
"*ded*",
"*****"]
Input ->
["aa",
"**",
"zz"]
Output ->
["****",
"*aa*",
"****",
"*zz*",
"****"]
테투리에 * 을 만듦.
for 문 2개로 조건문을 만들어서 할까 했는데,
1개씩 써서 순차적으로 만드는게 조건 확인하는 것 보다
빠를 것 같아서 한줄로 쭉 나열함
//Process
//1. Input characterVector (picture)
//2. Add * line for upper side of picture
//3. Add * to the begin and the end side on mid of picture
//4. Add * line for lower side of picture
//5. Return picture added all
//처리과정
//1. 글자 매트릭스를 입력받는다.
//2. 맨 위의 * 라인을 만들어 추가한다.
//3. 중간 기존 글자가 있는 곳 앞뒤로 * 을 추가한다.
//4. 맨 아래 * 라인을 만들어 추가한다.
//5. 만들어진 매트릭스를 반환한다.
Code... Let me see code!!!
코드... 코드를 보자!!!
std::vector<std::string> addBorder(std::vector<std::string> picture) {
int rows = picture.size();
int cols = picture.at(0).size();
std::string firstLine;
for (int i = 0; i < cols + 2; ++i) {
firstLine.push_back('*');
}
picture.insert(picture.begin(), firstLine);
for (inti = 0; i < rows; ++i) {
picture.at(i + 1).insert(picture.at(i + 1).begin(), '*');
picture.at(i + 1).push_back('*');
}
std::string lastLine;
for (int i = 0; i < cols + 2; ++i) {
lastLine.push_back('*');
}
picture.push_back(lastLine);
return picture;
}
Something else..
2018/10/08 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #12 SortByHeight
2018/10/06 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #11 IsLucky
2018/10/03 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #10 CommonCharacterCount
2018/09/26 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #9 AllLongestStrings
2018/09/24 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #8 MatrixElementsSum
2018/09/23 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #7 AlmostIncreasingSequence
2018/09/22 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #6 MakeArrayConsecutive2
2018/09/21 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #5 ShapeArea
2018/09/19 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #4 AdjacentElementsProduct
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #3 CheckPalindrome
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #2 CenturyFromYear
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #1 Add