Aracade Intro #53 validTime. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제,문제해결능력,example, c++ java c# scalar
Q.
Check if the given string is a correct time representation of the 24-hour clock.
주어진 문자열이 24시간을 나타내는 시간에 맞는지 확인해봐라
e.g.
Input -> time = "13:58"
Output -> validTime(time) = true
Input -> time = "25:51"
Output -> validTime(time) = false
Input -> time = "02:76"
Output -> validTime(time) = false
//Process
//2. Separate Hour and Minute
//3. Check if it's valid in 24hour time
//4. Return answer
//처리과정
//1. 문자열을 입력받는다.
//2. 시간과 분을 분리한다.
//3. 시간과 분이 24시 안에 들어가는지 확인한다.
//4. 결과를 반환한다.
Code.. Lemme see code!!!!!
코드.. 코드를 보자!!!!!
bool validTime(std::string time) {
bool answer = false;
string hour1(1, time[0]);
string hour2(1, time[1]);
string hour = hour1 + hour2;
string min1(1, time[3]);
string min2(1, time[4]);
string min = min1 + min2;
int intHour = std::stoi(hour);
int intMin = std::stoi(min);
cout << intHour << " " << intMin;
if (intHour >= 0 && intHour <= 23 && intMin >= 0 && intMin <= 59)
{
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/02 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #52 longestWord. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
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 효능/부작용/용법