• API
• FAQ
• Tools
• Archive
Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# Untitled

a guest Jun 13th, 2018 59 Never
ENDING IN00days00hours00mins00secs

1. #include <iomanip>
2. #include <iostream>
3. #include <cmath>
4. #include <cstdlib>
5.
6. using namespace std;
7.
8.
9. const string day_names[7] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
10.
11. const string day_short[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
12. const int days_month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
13.
14. bool is_leapyear(int year)
15. {
16.
17.     if(((year%4==0 && year%100 != 0) || (year%400 == 0)) || year < 1537) {
18.         return true;
19.     }
20.     return false;
21.
22.
23. }
24.
25.
26. int wday_jul(int day, int month, int year) {
27.
28.     int hjul;
29.
30.     hjul = day;
31.     hjul += floor((month+1)*26/10);
32.     hjul += year % 100;
33.     hjul += floor((year%100)/4);
34.     hjul += 5;
35.     hjul -= floor(year/100);
36.     hjul %= 7;
37.
38.     // swap
39.     return (hjul+6)%7;
40. }
41.
42.
43.
44. int wday_greg(int day, int month, int year) {
45.
46.
47.     int hgreg;
48.
49.     hgreg = day;
50.     hgreg += floor((month+1)*26/10);
51.     hgreg += year % 100;
52.     hgreg += floor((year%100)/4);
53.     hgreg += floor(floor(year/100)/4);
54.     hgreg -= 2*(floor(year/100));
55.     hgreg %= 7;
56.
57.     // swap
58.     return (hgreg+6)%7;
59.
60. }
61.
62.
63. int weekday(int day, int month, int year) {
64.
65.     int orig_year   = year;
66.     int orig_month = month;
67.
68.     if(month==1) {
69.         month = 13;
70.         year--;
71.     } else if(month==2) {
72.         month = 14;
73.         year--;
74.     }
75.
76.
77.     if(orig_year == 1582)
78.     {
79.         if(orig_month == 10)
80.         {
81.             if(day <= 4)
82.                 return wday_jul(day, month, year);
83.             if(day >= 15)
84.                 return wday_greg(day,month, year);
85.             else
86.                 return wday_greg(15, month, year);
87.
88.         }
89.         else if(orig_month < 10)
90.         {
91.             return wday_jul(day, month, year);
92.         }
93.         else
94.         {
95.             return wday_greg(day, month, year);
96.         }
97.     }
98.     else if(orig_year < 1582)
99.     {
100.         return wday_jul(day, month, year);
101.     }
102.     else
103.     {
104.         return wday_greg(day, month, year);
105.     }
106.
107.
108.
109. }
110.
111.
112. int* days_of_month(int month, int year) {
113.
114.     int* days = new int[31];
115.
116.     for(int i=0;i<31;i++) { days[i] = 0; }
117.
118.     if(year < 1582 || (year == 1582 && month < 10)) {
119.         for(int i=0;i<days_month[month-1];i++) {
120.             days[i] = i+1;
121.         }
122.     }
123.     else if(year > 1582 || (year==1582 && month > 10)) {
124.
125.         // feb has 28 days
126.         if(month == 2 && !is_leapyear(year)) {
127.             for(int i=0;i<28;i++) {
128.                 days[i] = i+1;
129.             }
130.         }
131.         else
132.         {
133.             for(int i=0;i<days_month[month-1];i++) {
134.                 days[i] = i+1;
135.             }
136.         }
137.     }
138.     else
139.     {
140.         for(int i=0;i<days_month[month-1];i++) {
141.
142.             if((i+1) <= 4 || (i+1) >= 15) {
143.                 days[i] = i+1;
144.             }
145.             else
146.             {
147.                 days[i] = 0;
148.             }
149.         }
150.     }
151.
152.     return days;
153.
154. }
155.
156. void print_cal(int day, int month, int year) {
157.
158.
159.     for(int i=0;i<7;i++) {
160.         cout<<setw(3)<<left<<day_short[i];
161.     }
162.
163.     cout<<endl;
164.
165.     int wday;
166.     int mday;
167.
168.     int* days = days_of_month(month, year);
169.
170.     for(int i=0;i<31;i++) {
171.
172.         mday = days[i];
173.
174.         if(mday == 0) { continue; }
175.
176.         wday = weekday(mday, month, year);
177.
178.         if(mday==1)
179.         {
180.             for(int j=0;j<wday;j++) {
181.                 cout<<setw(3)<<"   ";
182.             }
183.         }
184.
185.
186.         if(mday == day)
187.         {
188.             cout<<"\033[37;40m"<<setw(3)<<mday<<"\033[0m";
189.         }
190.         else
191.         {
192.             cout<<setw(3)<<mday;
193.         }
194.
195.
196.         if(wday==6) {
197.             cout<<endl;
198.         }
199.
200.     }
201.
202.     cout<<endl;
203.
204.
205. }
206.
207. int main(int argc, char* argv[])
208. {
209.
210.     int year;
211.     int month;
212.     int day;
213.
214.     day = atoi(argv[1]);
215.     month = atoi(argv[2]);
216.     year = atoi(argv[3]);
217.
218.
219.     print_cal(day, month, year);
220.
221.
222. return 0;
223. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top