#33920: C++參考


48985654 (天涯海神)

學校 : 不指定學校
編號 : 123240
來源 : [120.105.132.242]
最後登入時間 :
2023-03-27 09:02:37
c638. 天干地支 -- it's david | From: [223.141.64.161] | 發表日期 : 2023-02-13 20:48

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {

    
    int year;
    cout<<"請輸入1800-2018之間的一個年份"<<endl;
    cin>>year; 
    if(1800<=year && year<=2018){ 
        switch((year-1800)%10){        
        case 4:cout<<"甲";break;
        case 5:cout<<"乙";break;
        case 6:cout<<"丙";break;
        case 7:cout<<"丁";break;
        case 8:cout<<"戊";break;
        case 9:cout<<"已";break;
        case 0:cout<<"庚";break;
        case 1:cout<<"辛";break;
        case 2:cout<<"壬";break;
        case 3:cout<<"癸";break;
        }
        switch((year-1800)%12){
            case 0:cout<<"酉"<<endl;break;
            case 1:cout<<"戌"<<endl;break;
            case 2:cout<<"亥"<<endl;break;
            case 3:cout<<"子"<<endl;break;
            case 4:cout<<"丑"<<endl;break;
            case 5:cout<<"寅"<<endl;break;
            case 6:cout<<"卯"<<endl;break;
            case 7:cout<<"辰"<<endl;break;
            case 8:cout<<"巳"<<endl;break;
            case 9:cout<<"午"<<endl;break;
            case 10:cout<<"未"<<endl;break;
            case 11:cout<<"申"<<endl;break; 
        }
    }
    return 0;

}

 

 
ZeroJudge Forum