【go语言计算年龄生肖星座】go语言根据出生日期 计算年龄,所属星座,生肖

2024-09-07 07:38

本文主要是介绍【go语言计算年龄生肖星座】go语言根据出生日期 计算年龄,所属星座,生肖,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、需求分析
go语言根据出生日期 计算年龄,所属星座,生肖

二、运行效果

"D:\Program Files (x86)\JetBrains\Gogland 171.3780.106\bin\runnerw.exe" D:/Go\bin\go.exe run D:/Go/code/src/awesomeProject/age_calculate.go
24 狮子座 鸡Process finished with exit code 0

三、实现源代码

package mainimport (
"fmt"
"time"
)func GetTimeFromStrDate(date string) (year, month, day int) {const shortForm = "2006-01-02"d, err := time.Parse(shortForm, date)if err != nil {fmt.Println("出生日期解析错误!")return 0,0,0}year = d.Year()month = int(d.Month())day = d.Day()return
}func GetZodiac(year int) (zodiac string) {if year <= 0 {zodiac = "-1"}start := 1901x := (start - year) % 12if x == 1 || x == -11 {zodiac = "鼠"}if x == 0 {zodiac = "牛"}if x == 11 || x == -1 {zodiac = "虎"}if x == 10 || x == -2 {zodiac = "兔"}if x == 9 || x == -3 {zodiac = "龙"}if x == 8 || x == -4 {zodiac = "蛇"}if x == 7 || x == -5 {zodiac = "马"}if x == 6 || x == -6 {zodiac = "羊"}if x == 5 || x == -7 {zodiac = "猴"}if x == 4 || x == -8 {zodiac = "鸡"}if x == 3 || x == -9 {zodiac = "狗"}if x == 2 || x == -10 {zodiac = "猪"}return
}func GetAge(year int) (age int) {if year <= 0 {age = -1}nowyear := time.Now().Year()age = nowyear - yearreturn
}func GetConstellation(month, day int) (star string) {if month <= 0 || month >= 13 {star = "-1"}if day <= 0 || day >= 32 {star = "-1"}if (month == 1 && day >= 20) || (month == 2 && day <= 18) {star = "水瓶座"}if (month == 2 && day >= 19) || (month == 3 && day <= 20) {star = "双鱼座"}if (month == 3 && day >= 21) || (month == 4 && day <= 19) {star = "白羊座"}if (month == 4 && day >= 20) || (month == 5 && day <= 20) {star = "金牛座"}if (month == 5 && day >= 21) || (month == 6 && day <= 21) {star = "双子座"}if (month == 6 && day >= 22) || (month == 7 && day <= 22) {star = "巨蟹座"}if (month == 7 && day >= 23) || (month == 8 && day <= 22) {star = "狮子座"}if (month == 8 && day >= 23) || (month == 9 && day <= 22) {star = "处女座"}if (month == 9 && day >= 23) || (month == 10 && day <= 22) {star = "天秤座"}if (month == 10 && day >= 23) || (month == 11 && day <= 21) {star = "天蝎座"}if (month == 11 && day >= 22) || (month == 12 && day <= 21) {star = "射手座"}if (month == 12 && day >= 22) || (month == 1 && day <= 19) {star = "魔蝎座"}return star
}func main() {y, m, d := GetTimeFromStrDate("1993-08-20")fmt.Println(GetAge(y),GetConstellation(m, d),GetZodiac(y))}

这篇关于【go语言计算年龄生肖星座】go语言根据出生日期 计算年龄,所属星座,生肖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144471

相关文章

科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)

介绍 R语言的扩展物种堆积图是一种数据可视化工具,它不仅展示了物种的堆积结果,还整合了不同样本分组之间的差异性分析结果。这种图形表示方法能够直观地比较不同物种在各个分组中的显著性差异,为研究者提供了一种有效的数据解读方式。 加载R包 knitr::opts_chunk$set(warning = F, message = F)library(tidyverse)library(phyl

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

uva 11178 计算集合模板题

题意: 求三角形行三个角三等分点射线交出的内三角形坐标。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

Go Playground 在线编程环境

For all examples in this and the next chapter, we will use Go Playground. Go Playground represents a web service that can run programs written in Go. It can be opened in a web browser using the follow

go基础知识归纳总结

无缓冲的 channel 和有缓冲的 channel 的区别? 在 Go 语言中,channel 是用来在 goroutines 之间传递数据的主要机制。它们有两种类型:无缓冲的 channel 和有缓冲的 channel。 无缓冲的 channel 行为:无缓冲的 channel 是一种同步的通信方式,发送和接收必须同时发生。如果一个 goroutine 试图通过无缓冲 channel

C语言 | Leetcode C语言题解之第393题UTF-8编码验证

题目: 题解: static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num & MASK1) == 0) {return

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX