GP31. 年龄分段
描述
示例1
输入:
35
输出:
"青年"
Go 解法, 执行用时: 3ms, 内存消耗: 804KB, 提交时间: 2022-06-08
package main func getAge(age int) string { a := "" switch { case age < 1 && age >= 0: a = "婴儿" case age <= 4 && age >= 1: a = "幼儿" case age <= 11 && age >= 5: a = "儿童" case age <= 18 && age >= 12: a = "少年" case age <= 35 && age >= 19: a = "青年" case age <= 59 && age >= 36: a = "中年" case age >= 60: a = "老年" } return a }
Go 解法, 执行用时: 3ms, 内存消耗: 828KB, 提交时间: 2022-06-06
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param age int整型 年龄 * @return string字符串 */ func getAge( age int ) string { // write code here var res string switch { case age < 1 && age >= 0: res = "婴儿" case age <= 4 && age >= 1: res = "幼儿" case age <= 11 && age >= 5: res = "儿童" case age <= 18 && age >= 12: res = "少年" case age <= 35 && age >= 19: res = "青年" case age <= 59 && age >= 36: res = "中年" case age >= 60: res = "老年" } return res }
Go 解法, 执行用时: 3ms, 内存消耗: 860KB, 提交时间: 2022-06-10
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param age int整型 年龄 * @return string字符串 */ func getAge( age int ) string { // write code here switch { case age >= 0 && age < 1: return "婴儿" case age >= 1 && age < 5: return "幼儿" case age >= 5 && age < 12: return "儿童" case age >= 12 && age < 19: return "少年" case age >= 19 && age < 36: return "青年" case age >= 36 && age < 60: return "中年" case age >= 60: return "老年" default: return "" } }
Go 解法, 执行用时: 3ms, 内存消耗: 888KB, 提交时间: 2022-07-25
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param age int整型 年龄 * @return string字符串 */ func getAge( age int ) string { // write code here var s string switch { case age >= 0 && age <1 : s= "婴儿" case age >= 1 && age <=4: s= "幼儿" case age >= 5 && age <=11: s= "儿童" case age >= 12 && age <=18: s= "少年" case age >= 19 && age <=35: s= "青年" case age >= 36 && age <=59: s= "中年" case age >= 60: s= "老年" } return s }
Go 解法, 执行用时: 3ms, 内存消耗: 888KB, 提交时间: 2022-06-12
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param age int整型 年龄 * @return string字符串 */ func getAge( age int ) string { // write code here var ans string switch { case age <1 && age >= 0: ans = "婴儿" case age >=1 && age <= 4: ans = "幼儿" case age >= 5 && age <= 11: ans = "儿童" case age >= 12 && age <= 18: ans = "少年" case age >= 19 && age <= 35: ans = "青年" case age >=36 && age <=59: ans = "中年" case age >= 60: ans = "老年" } return ans }