using System;
using System.Text.RegularExpressions;

namespace MyId
{
    class Program
    {
        static void Main(string[] args)
        {
            
            Console.Write("请输入18位身份证号码:");
            string ageText;
            try
            {
                ageText = Console.ReadLine();
                Regex r = new Regex(@"^-?\d+$");
                if (ageText.Length == 18&&r.IsMatch(ageText))
                {
                    string tmp = ageText.Substring(6, 8);//截取生日信息
                    tmp = tmp.Insert(4, "年").Insert(7, "月") + "日";//在字符串相应位置插入字符
                    Console.WriteLine(tmp);
                    if (int.Parse(ageText.Substring(14, 3)) % 2 == 0)//根据身份证号码标准格式确认男女,偶数为女,奇数为男
                    {
                        Console.WriteLine("女");
                    }
                    else
                    {
                        Console.WriteLine("男");
                    }
                }
                else
                {
                    throw new Exception("身份证号码不正确!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
    }
}