Java basics-interesting Yin/yang calendar interchange Algorithms

Source: Internet
Author: User

Program:
// Calendar lunar Conversion Program



Prototype: int calconv (struct convdate *);

Struct convdate
{
Int source; = 0, the input date is the West calendar ,! If the value is 0, the input is the lunar calendar.
Int solaryear; Year of the input or output calendar
Int solarmonth; calendar month
Int solardate; calendar day
Int lunaryear; Year of the input or output calendar year
Int lunarmonth; lunar month
Int lunardate; lunar day
Int weekday; the day of the week (0 = Sunday, 1 = Monday ,...)
Int kan; dry day (0 = A, 1 = B,..., 9 =)
Int chih; Day (0 = Child, 1 = ugly,..., 11 = Hai)
};

The value of souce must be set during the call. If it is 0, it is the conversion from the West calendar to the lunar calendar. Otherwise, it is the conversion from the lunar calendar to the west calendar.
Enter the year, month, and day of the West or lunar calendar. The year, month, and day after the conversion will be filled in the structure (
And the day of the week.
If the return value of the function is 0, it indicates that there is no error. 1 indicates that the input year is incorrect, and 2 indicates that the input month is incorrect,
3. The input date is incorrect.
The entered calendar year must be in the range of 1937-2031
The input calendar year must be between 1936 and 2030
If expansion is required, lunarcal [] is added.

*/

# Define firstyear 1936/* the first year in lunarcal [] */

Struct convdate
{
Int source;
Int solaryear;
Int solarmonth;
Int solardate;
Int lunaryear;
Int lunarmonth;
Int lunardate;
Int weekday;
Int kan;
Int chih;
};

Struct taglunarcal
{
Int basedays;/* cumulative number of days from January 1 to lunar January 1 x */
Int intercalation;/* leap month. 0 = No leap month in this year */
Int baseweekday;/* the day of the week minus 1 in the calendar month */
Int basekanchih;/* The number of the trunk branch number minus 1 */
Int monthdays [13];/* the monthly size of this Lunar year, 0 = Small month (29 days), 1 = large month (30 days )*/
};

Struct taglunarcal lunarcal [] = {
{23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0 }, /X 1936 */
{41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 },
{30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1 },
{49, 0, 6, 33, 1, 1, 0, 0, 1, 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, 0, 0, 1, 0, 0, 1 },
{44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1 },
{33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1 },
{22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 0 }, /X 2012 */
{40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0 },
{30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1 },
{49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },
{38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0 }, /X 2016 */
{27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
{46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0 },
{24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1 }, /X 2020 */
{42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1 },
{31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0 },
{21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1 },
{40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 }, /X 2024 */
{28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
{36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1 },
{25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0 }, /X 2028 */
{43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1 },
{32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 0 },

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.