07:05:45PM
19:05:45
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func timeConversion(str string) string { times := make([]string, 3) times[0] = str[0:2] times[1] = str[3:5] times[2] = str[6:8] tail := str[8:10] switch tail { case "AM": mt, _ := strconv.Atoi(times[0]) times[0] = fmt.Sprintf("%02d", func(arg int) int { if arg == 12 { return 0 } return arg }(mt)) return strings.Join(times, ":") case "PM": mt, _ := strconv.Atoi(times[0]) times[0] = fmt.Sprintf("%02d", func(arg int) int { if arg == 12 { return 12 } return arg + 12 }(mt)) return strings.Join(times, ":") default: return "error" } } func main() { reader := bufio.NewReader(os.Stdin) inputTime, _ := reader.ReadString('\n') inputTime = strings.Trim(inputTime, "\n") fmt.Println(timeConversion(inputTime)) }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
시간변환
입력 형식
출력 포맷
예제
문제풀이
golang
Recent Posts
Archive Posts
Tags