AllLongestStrings
Given an array of strings, returns another array containing all of it's longest strings
입력받은 문자 배열에서, 가장 긴 문자들만 따로 뽑은 배열을 리턴해라
//Process
//1. Input strings array
//2. Iterate from begin to the end
// 2.1. Check string's length
// 2.2. If it's longer than longest string, -> make new output longest string array
// 2.3. If it's same length, -> add
//3. Return outputArray
//처리과정
//1. 문자배열을 입력받는다.
//2. 입력받은 배열 시작부터 끝까지 반복한다.
// 2.1. 문자 길이를 확인한다.
// 2.2. 가장 긴 문자길이보다 길면 -> 새로 가장 긴 문자 배열을 만든다
// 2.3. 가장 긴 문자길이와 같으면 -> 추가한다.
//3. 가장 긴 길이의 문자들 배열을 반환한다.
std::vector<std::string> allLongestStrings(std::vector<std::string> inputStrings) {
vector<string> longestStrings;
int maxLength = 0;
int length = inputStrings.size();
for (int i = 0; i < length; ++i) {
int strLength = inputStrings[i].length();
if (maxLength < strLength)
{
longestStrings.clear();
longestStrings.push_back(inputStrings[i]);
maxLength = strLength;
}
else if (maxLength == strLength)
{
longestStrings.push_back(inputStrings[i]);
}
}
return longestStrings;
}
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
'Algorithm > Code Fights (Code Signal)' 카테고리의 다른 글
Aracade Intro #11 IsLucky (0) | 2018.10.06 |
---|---|
Aracade Intro #10 CommonCharacterCount (0) | 2018.10.03 |
Aracade Intro #8 MatrixElementsSum (0) | 2018.09.24 |
Aracade Intro #7 AlmostIncreasingSequence (0) | 2018.09.23 |
Aracade Intro #6 MakeArrayConsecutive2 (0) | 2018.09.22 |