본문 바로가기

Computer Science/C#

0912


 using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class idNum
    {
        public static void Main()
        {
            string num;
            string year;
            string month;
            string day;
            string age;
            string gender;
            string nowYear;

            Console.WriteLine("주민번호를 입력하세요:");
            num = Console.ReadLine();
           
            //Console.WriteLine("{0} : {1}", num,Convert.ToInt32(num)+1); 변환 확인

            year = num.Substring(0,2);
            Console.WriteLine("당신이 태어난 년도는 {0}",year);

            month = num.Substring(2,2);
            Console.WriteLine("당신이 태어난 월은 {0}",month);

            day = num.Substring(4,2);
            Console.WriteLine("당신이 태어난 날은 {0}",day);

            nowYear = Convert.ToString(DateTime.Now).Substring(0, 4);
            //Console.WriteLine("{0}", nowYear);

            if(num.Substring(0,1)!="0")
                age = Convert.ToString(Convert.ToUInt32(nowYear)+1 - Convert.ToInt32(year) -1900);
            else
                age = Convert.ToString(Convert.ToUInt32(nowYear) + 1 - Convert.ToInt32(year) - 2000);
            Console.WriteLine("당신의 나이는  {0}",age);
           
            gender = num.Substring(6,1);

            if(gender =="1" || gender =="3")
            Console.WriteLine("당신의 성별은 남자입니다.");
            else if(gender =="2" || gender =="4")
                Console.WriteLine("당신의 성별은 여자입니다.");
        }
    }
}