精華區beta C_and_CPP 關於我們 聯絡資訊
// 我是以1995年一月一日為基準點 //  // 計算出輸入者所輸入月份的第一天和1995.01.01.差多少天 // // 大致上是這樣子吧 // #include <iostream.h> #include <iomanip.h> #include <conio.h> #include <stdio.h> int detect (int); void display (int,int,int,int); void locate (int,int,int); int main() { int year,month; int i,mday,mfweek,mdelta,le1; char flag; long delta; int m[12]; m[0]=31; m[2]=31; m[3]=30; m[4]=31; m[5]=30; m[6]=31; m[7]=31; m[8]=30; m[9]=31; m[10]=30; m[11]=31; m[1]=0; while (1) { mdelta=0; delta=0; i=0; mday=0; mfweek=0; flag='\0'; le1=1; clrscr(); gotoxy (1,25); cout <<"Please input the year:"; cin >>year; while (le1) { clrscr(); flag='\0'; gotoxy (1,25); cout <<"Please input the month:"; cin >>month; if (year>1995) { for (i=1995;i<year;i++) { if (detect(i)) delta=delta+366; else delta=delta+365; } } if (year<1995) { for (i=year;i<1995;i++) { if (detect(i)) delta=delta+366; else delta=delta+365; } delta=-delta; } m[1]=detect(year)+28; for (i=0;i<(month-1);i++) { mdelta=mdelta+m[i]; } delta=delta+mdelta; mfweek=((delta%7)+7)%7; mday=m[month-1]; display (year,month,mday,mfweek); gotoxy (1,25); cout <<"1) Input the year/month. 2) Quit. :"; cin >>flag; if (flag=='1') le1=0; if (flag=='2') return 0; } } } int detect (int year) { int r; if (year%4==0) { if (year%100==0) { if (year%400==0) r=1; else r=0; } else r=1; } else r=0; return r; } void display (int year,int month,int mday,int mfweek) { clrscr(); int d,w,n; d=mfweek; w=1; n=1; gotoxy (25,1); cout <<year<<" "<<month<<endl; cout <<" *********************************************"; gotoxy (7,5); cout <<"Sun Mon Tue Wed Thu Fri Sat"; while (n<=mday) { d++; if (d==8) { d=1; w++; } locate (d,w,n); n++; } } void locate(int d,int w,int n) { int x,y; x=d*7; y=w*3+4; if (n<10) x++; gotoxy (x,y); cout <<n<<endl; } -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: ccsun2.ee.ntu.edu.tw