Simulate time-based conversion and output current year calendar

Source: Internet
Author: User

This is a friend entrusted me to play, do not belong to ACM, but feel very interesting, so put here, the topic has two requirements, output when the 1 years January 1 to the year before the month before the 1th number of days separated, and output this day is the days of the week, and then output this year in the format of 12 months of the Gregorian calendar.

is a very simple simulation, is a little bit of trouble and small details to note, the following is the code:

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;structnode{intY,m,d,day;}; Node start;voidinit () {Start.y=1; START.M=1; START.D=1; Start.day=1;}BOOLIs_leap (intYear ) {    if(year% -==0|| (year%4==0&&year% -!=0))return true; Else return false;}intDay_of_month (intYearintm) {    if(m==1|| m==3|| m==5|| m==7|| m==8|| m==Ten|| m== A)return  to; if(m==2)    {        if(Is_leap (year))return  in; return  -; }    return  -;} Node tmp;intgetday (Node now) {tmp=start; intAns =0; BOOLFlag =false;  while(tmp.y<=now.y) { while(tmp.m <= A)        {             while(TMP.D <=Day_of_month (tmp.y,tmp.m)) {                if(tmp.y==now.y&&tmp.m==now.m&&tmp.d==now.d) {flag=true;  Break; } TMP.D++; Tmp.day++; if(tmp.day==8) {Tmp.day=1; }                ///cout<< "Year Month Day D:" <<tmp.y<< "<<tmp.m<<" "<<tmp.d<<" "<< tmp.day<<endl;ans++;            }            if(flag) Break; TMP.D=1; TMP.M++; }        if(flag) Break; TMP.M=1; TMP.Y++; }    returnans;}intMain () {intnowyear; scanf ("%d",&nowyear);    Init ();    Node now; Now.y=nowyear; NOW.D=1; intfirstday[ -]; intallday[ -];  for(inti =1; I <= A; i++) {now.m=i; intres =Getday (now); printf ("%d days%d months, 1th .", Nowyear,i,res); printf ("This is the day of the week%d\n", Tmp.day); Firstday[i]=Tmp.day; Allday[i]=Day_of_month (nowyear,i); Puts (""); }     for(inti =1; I <= A; i++) {printf ("%d months \ n", i); printf ("-----------------------\ n"); ///printf ("7 1 2 3 4 5 6\n");printf"Day 123456 \ n"); intKey =Firstday[i]; ///cout<< "key =" <<key<<endl;if (Key< 7)        {             for(intj =1; J <= key;j++) cout<<"   "; }        inttot =1, K1 = key==7?7:7-key,k0 =0; BOOLMark =false;  while(Tot <=Allday[i]) {printf ("%3d", tot); K0++; Tot++; if(K0==K1 &&!)Mark) {Puts (""); K0=0; Mark=true; }            if(mark&&k0==7) {puts (""); K0=0; }} puts (""); }    return 0;}

Simulate time-based conversion and output current year calendar

Related Article

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.