Aracade Intro #52 longestWord. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
Q.
Define a word as a sequence of consecutive English letters. Find the longest word from the given string.
단어를 일련된 영문자들의 연속으로 정의해라. 주어진 문자열에서 가장 긴 단어를 찾아라.
e.g.
Input -> text = "Ready, steady, go!"
Output -> longestWord(text) = "steady"
//Process
//1. Input text
//2. Iterate from begin to the end
// 2.1. Check if it's alphabet or not
// 2.1.1. if so - add to tempString
// 2.1.2. if not - compare with answerString length
// 2.1.2.1. if tempString is longer than answerString -> replace them
// 2.1.2.2. if not -> pass
//3. Return answerString
//처리과정
//1. 문자열을 입력받는다.
//2. 시작부터 끝까지 반복한다.
// 2.1. 알파벳인지 아닌지 확인해서
// 2.1.1. 맞으면 -> tempString 에 더해둔다
// 2.1.2. 아니면 -> tempString 과 answerString 길이를 비교해서
// 2.1.2.1 tempString이 더 길면 교체한다.
//3. answerString을 반환한다.
Code.. Lemme see code!!!!!
코드.. 코드를 보자!!!!!
std::string longestWord(std::string text) {
string answerString = "";
string tempString = "";
for (int i = 0; i < text.size(); ++i)
{
if (isAlphabet(text[i]))
{
tempString += text[i];
if (i == text.size() - 1 && answerString.size() < tempString.size())
{
answerString = tempString;
}
}
else
{
if (answerString.size() < tempString.size())
{
answerString = tempString;
}
tempString = "";
}
}
return answerString;
}
bool isAlphabet(char& text) {
bool answer = false;
if ((text >= 'a' && text <= 'z') || (text >= 'A' && text <= 'Z'))
{
answer = true;
}
return answer;
}
Something else you might like..
2018/12/26 - [Programming/Design Pattern ] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍
2019/01/01 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #51 deleteDigit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/31 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #50 chessKnight. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/28 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #49 lineEncoding. Algorithm, 알고리즘 문제풀이, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #48 isDigit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #47 isMAC48Address. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/25 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #46 electionsWinners. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #45 buildPalindrome. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #44 findEmailDomain. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/17 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #43 isBeautifulString. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #42 bishopAndPawn. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/14 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #41 digitDegree. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #40 longestDigitsPrefix. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/10 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #39 knapsackLight. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/12/20 - [Programming/Java] - How to convert file to byte array (byte[]) example, 파일 객체 바이트로 변환하기 예제코드, java/cpp/c++/scalar
2018/12/18 - [Programming/Java] - How to access controller from existing Pane in JavaFX, pane에서 해당 controller로 접근하기, java/cpp/c++/fx/gui
2018/12/13 - [Computer/Linux] - How to check ongoing live process on Linux cmd, 리눅스 커맨드창에서 어떤 프로세스가 실행중인지 확인하기, java, ubuntu, cpp
2018/12/27 - [Life/Health care] - Milk-Thistle 밀크시슬 usage/side effects/dosage/fatigue/supplement,효능/부작용/성인,소아 용법/건강/피로회복/영양제
2018/12/16 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법(2)
2018/12/06 - [Life/Health care] - Vitamin C 비타민 씨 usage/side effects/dosage 용법/효능/부작용
2018/12/02 - [Life/Health care] - Maca 마카 usage/side effects/dosage 효능/부작용/용법