Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money
【PTA group Program Design Ladder Competition 】
Best couple height difference L1-040 (10) the Go | Golang
Using data from multiple couples, experts found that the optimal height difference follows a formula: the woman’s height ×1.09 = the man’s height. If so, the height difference between the two of you, whether holding hands, hugging, or kissing, is the most harmonious difference.
Here you write a program, for any user to calculate the best height of his/her lovers.
Input format:
Enter the positive integer N (≤10) in the first line, which is the number of users to be queried. Then N lines, each line gives the gender and height of the user to query according to the format of “gender height”, where “gender” is “F” for female, “M” for male; “Height” is a real number between [1.0, 3.0].
Output format:
For each query, calculate the optimal height of the couple for that user in one line, with two decimal places to spare.
Input Example 1:
2 M 1.75f 1.8Copy the code
No blank line at the end
Example 1:
1.61
1.96
Copy the code
No blank line at the end
Ideas:
Basic judgment statement, with array storage is good, the final output of the time to retain the decimal is good ~
The code is as follows:
package main
import "fmt"
func main(a) {
var num int
var numList []float64
_,_=fmt.Scan(&num)
for i := 0; i < num; i++ {
var str string
var n float64
_,_=fmt.Scan(&str,&n)
if str == "F" {
numList = append(numList,n*1.09) // (woman's height) ×1.09 = (man's height)
}else{
numList = append(numList,n/1.09)}}for i := 0; i < len(numList); i++ {
if i==0 {
fmt.Printf("%.2f",numList[i])
}else{
fmt.Printf("\n%.2f",numList[i])
}
}
}
Copy the code