Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

【PTA group Program Design Ladder Competition 】

Big Ben L1-018 (10) the Go | Golang

On Weibo, a guy who calls himself “Big Ben V” strikes the bell every day to urge farmers to take good care of their bodies and go to bed early. However, because of his own work and rest is not very regular, so the bell does not ring regularly. Generally, the number of bells is determined according to the time of the bell. If it happens to be struck at a certain hour, the number of “when” is equal to the number of the hour. If the hour has passed, the next hour is struck. In addition, although there are 24 hours in a day, the clock only strikes 1~12 times in the second half of the day. For example, when the bell strikes at 23:00, it’s “knock knock knock knock knock knock knock knock knock”, while at 23:01, it’s “knock knock knock knock knock knock knock knock”. The clock does not strike between 00:00 midnight and 12:00 noon (endpoints included).

Please write a program, according to the current time for Big Ben bell.

Input format:

Enter the first line to give the current time in hh:mm format. Where hh is hour, between 00 and 23; Mm is minutes, between 00 and 59.

Output format:

Ring Big Ben according to the current time, that is, output the corresponding amount in a line is ·Dang. If not, output: Only hh:mm. Too early to Dang.

Input Example 1:

19:05
Copy the code

No blank line at the end

Example 1:

DangDangDangDangDangDangDangDang
Copy the code

No blank line at the end

Input Example 2:

07:05
Copy the code

No blank line at the end

Example 2:

Only 07:05.  Too early to Dang.
Copy the code

No blank line at the end

Ideas:

Basic judgment statement, the hour is judged first, and then the minute is judged when the condition is met. Then determine how many Dang to add

The code is as follows:

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main(a) {
	var time string
	_,_=fmt.Scan(&time)
	tmp := strings.Split(time,":")
	hour,_ := strconv.Atoi(tmp[0])
	second,_ := strconv.Atoi(tmp[1])
	str := ""
	if hour>=00 && hour<=12 { 
		fmt.Printf("Only %s:%s. Too early to Dang.",tmp[0],tmp[1])
		return
	}else{
		for i:=0; i<hour- 12; i++ {
			str += "Dang"}}ifsecond! =0 { // If you strike at a certain hour, then the "when" number equals that hour number
				   // If the hour has passed, then the next hour is 0. If this is not 0, then it is not the hour.
		str +="Dang"
	}
	fmt.Printf(str)
}
Copy the code