“This is the ninth day of my participation in the First Challenge 2022. For details: First Challenge 2022”

I. Problem description

Ancient China used heavenly stems and earthly branches to record the current year.

There are ten celestial stems in total, which are ǐ jia, y, B, D īng, wu, J ǎ ng, G īng, xīn, ren, and GUI.

There are twelve earthly branches in total, which are: Z ǐ, CH ǒu, Yin, M ǎo, Chen, Si, W ǔ, Wei, Shen, yǒu, xū, hai.

A year of heavenly stems and earthly branches is formed by connecting heavenly stems and earthly branches, such as Jia Zi.

With each passing year, the stems and branches move on to the next. For example, 2021 is the Year of Xin Chou.

Every 60 years, the heavenly stem will cycle 6 times, the earth branch will cycle 5 times, so the heavenly stem earth branch chronological cycle every 60 years. For example, 1900, 1960 and 2020 are the year of Gengzi.

Given a A.D. year, output the year of the celestial stem and terrestrial branch for that year.

Two, the title requirements

The input line contains a positive integer representing the YEAR.

The entered YEAR must be a positive integer not exceeding 9999.

Third, problem analysis

The title has 10 heavenly stems and 12 earthly branches. The first elements of the heavenly stems and earthly branches are respectively A and Zi. Since the heavenly stems and earthly branches cycle once every 60 years, it doesn’t matter who the first element is. 1200 as a base for calculating other years, it’s pretty clear whether it’s mod 10 or mod 12.

Defines two string array stores of strings in any order. How to select a standard year as the base for any year. Such as:

string a[10] = {"geng", "xin", "ren", "gui", "jia", "yi" , "bing", "ding", "wu", "ji"};

string b[12] = {"shen", "you", "xu", "hai", "zi", "chou", "yin", "mou", "chen", "si", 

"wu", "wei"};
Copy the code

For a given year, say, 2022 nonyin year, 2022%10==2, so the first term is ren. 12==6, so the tail term is Yin.

Four, coding implementation

#include <iostream>
using namespace std;
int main(a)
{
    int year;
    cin >> year;// Define the year, terminal input the year
   	string a[10] = {"geng"."xin"."ren"."gui"."jia"."yi" , "bing"."ding"."wu"."ji"};
        // Array A stores the sky stem
   	string b[12] = {"shen"."you"."xu"."hai"."zi"."chou"."yin"."mou"."chen"."si"."wu"."wei"};
        // Array B stores the base
   	cout << a[year % 10] << b[year % 12];// For a given year
   return 0;
}
Copy the code

4. Output results

For example, in 2022, renyin is displayed.