zoukankan      html  css  js  c++  java
  • c#之根据出生日期获得星座信息

    星座定义如下:

    代码如下:

        public enum Constellation
        {
            Aquarius = 1,       // 水瓶座 1.20 - 2.18
            Pisces = 2,         // 双鱼座 2.19 - 3.20
            Aries = 3,          // 白羊座 3.21 - 4.19
            Taurus = 4,         // 金牛座 4.20 - 5.20
            Gemini = 5,         // 双子座 5.21 - 6.21
            Cancer = 6,         // 巨蟹座 6.22 - 7.22
            Leo = 7,            // 狮子座 7.23 - 8.22
            Virgo = 8,          // 处女座 8.23 - 9.22
            Libra = 9,          // 天秤座 9.23 - 10.23
            Acrab = 10,         // 天蝎座 10.24 - 11.22
            Sagittarius = 11,   // 射手座 11.23 - 12.21
            Capricornus = 12,   // 摩羯座 12.22 - 1.19
        }
    
        // 根据出生日期获得星座信息
        public static Constellation GetConstellation(int birthMonth, int birthDate)
        {
            float birthdayF = birthMonth == 1 && birthDate < 20 ?
                13 + birthDate / 100f :
                birthMonth + birthDate / 100f;
    
            float[] bound = { 1.20F, 2.20F, 3.21F, 4.21F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.23F, 11.21F, 12.22F, 13.20F };
    
            Constellation[] constellations = new Constellation[12];
            for (int i = 0; i < constellations.Length; i++)
                constellations[i] = (Constellation)(i + 1);
    
            for (int i = 0; i < bound.Length - 1; i++)
            {
                float b = bound[i];
                float nextB = bound[i + 1];
                if (birthdayF >= b && birthdayF < nextB)
                    return constellations[i];
            }
    
            return Constellation.Acrab;
        }
  • 相关阅读:
    P1141零一迷宫
    P1219八皇后
    P1233木棍加工
    三 Struts2 添加返回数据
    二 Struts2 接收数据
    一 Struts2 开发流程
    12-tinyMCE文本编辑器+图片上传预览+页面倒计时自动跳转
    11-page分页原理
    10-ajax技术简介
    9-文件上传和下载
  • 原文地址:https://www.cnblogs.com/jietian331/p/7717548.html
Copyright © 2011-2022 走看看