Advertisement
protonchang

萬年歷 Beta 1

Oct 25th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     int date,months,days,years,years_thousand,years_hundred,years_ten,years_one,years_stg_one,years_stg_two;
  7.     cout<<"請輸入年/月/日,用空格分開: ";
  8.     cin>>years>>months>>date;
  9.     if (months == 1) {
  10.         months = 13;
  11.         years = years-1;
  12.     }
  13.     if (months == 2) {
  14.         months=14;
  15.         years = years-1;
  16.     }
  17.     years_thousand=years/1000;
  18.     years_hundred=(years-years_thousand*1000)/100;
  19.     years_ten=(years-years_thousand*1000-years_hundred*100)/10;
  20.     years_one=(years-years_thousand*1000-years_hundred*100-years_ten*10);
  21.     /*
  22.     cout<<"years = "<<years<<endl;
  23.     cout<<"years thousand = "<<years_thousand<<endl;;
  24.     cout<<"Years hundred = "<<years_hundred<<endl;
  25.     cout<<"Years ten = "<<years_ten<<endl;
  26.     cout<<"Years one = "<<years_one<<endl;
  27.     */
  28.     years_stg_one=10*years_thousand+years_hundred;
  29.     years_stg_two=10*years_ten+years_one;
  30.     if (years_stg_one<=15 && years_stg_two<=82 && months<=10 && days<=4) {
  31.         goto befcalc;
  32.     }
  33.     else {
  34.         goto afcalc;
  35.     }
  36. befcalc:
  37. {
  38.     days=(years_stg_two+(years_stg_two/4)-years_stg_one+(26*(months+1)/10)+date+4)%7-1;
  39.     if (days == 0) {
  40.         cout<<"星期天"<<endl;
  41.     }
  42.     else if (days<0) {
  43.         days = days + 7;
  44.         cout<<"星期"<<days<<endl;
  45.     }
  46.     else {
  47.         cout<<"星期"<<days<<endl;
  48.     }
  49.     cout<<(26*(months+1)/10);
  50.     return 0;
  51. }
  52. afcalc:
  53. {
  54.     days=(years_stg_two+(years_stg_two/4)+(years_stg_one/4)-2*years_stg_one+(26*(months+1)/10)+date-1)%7;
  55.     if (days == 0) {
  56.         cout<<"星期天"<<endl;
  57.     }
  58.     else if (days<0) {
  59.         days = (days%7+7)%7;
  60.         cout<<"星期"<<days<<endl;
  61.     }
  62.     else {
  63.         cout<<"星期"<<days<<endl;
  64.     }
  65.     return 0;
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement