IT 개발자_S

해커랭크 TIME Conversion python 본문

IT/알고리즘_Python

해커랭크 TIME Conversion python

Soso12 2020. 3. 12. 13:15
반응형

#!/bin/python3

import os
import sys

#
# Complete the timeConversion function below.
#
def timeConversion(s):
    #
    # Write your code here.
    #

    time =0
    if 'PM' in (s) :  ## PM 일경구
        time = abs(int(s[0:2]) +12)
        if(s[0:2] == '12') :
            time =12
        s = s.replace(s[0:2], str(time))
        return(s[0:-2].zfill(8))
    
    else :
        if( int(s[0:2]) < 12):  ## 12시 이전 값들은 동일하게
            time = int(s[0:2])

        else :  ## 12시가 넘어가게되면 12를 빼줌
            time = abs(int(s[0:2]) -12)

        if(s[0:2] == '12') :
            time = str(00)
        s =s.replace(s[0:2], str(time))
    
        return(s[0:-2].zfill(8))  ## 8자리로 고정 

if __name__ == '__main__':
    f = open(os.environ['OUTPUT_PATH'], 'w')

    s = input()

    result = timeConversion(s)

    f.write(result + '\n')

    f.close()

반응형

'IT > 알고리즘_Python' 카테고리의 다른 글

해커랭크 Breaking the Records  (0) 2020.03.22
해커랭크 Kangaroo PYTHON  (0) 2020.03.13
해커랭크 Apple and Orange  (0) 2020.03.12
해커랭크 Grading Strudents  (0) 2020.03.12
해커랭크 Birthday Cake Candles  (0) 2020.03.10
Comments