Created
November 26, 2018 10:01
-
-
Save long25vn/95a434b4b228847ddee84b6c05f1ad1f to your computer and use it in GitHub Desktop.
Doomsday created by long25vn - https://repl.it/@long25vn/Doomsday
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://en.wikipedia.org/wiki/Doomsday_rule | |
| #include <stdio.h> | |
| #include<iostream> | |
| #include<math.h> | |
| #include<iomanip> | |
| using namespace std; | |
| main() | |
| { | |
| int *p1; | |
| int a,b,c,d; | |
| int day,month,year; | |
| int arr[6][7]; | |
| for(int row = 0; row < 6; row++) | |
| { | |
| for(int col = 0; col < 7; col++) | |
| { | |
| arr[row][col]=0; | |
| } | |
| } | |
| int temp=1; | |
| int temp1=0; | |
| cout << "Nhap thang:" << endl; | |
| cin >> month; | |
| cout << "Nhap nam:" << endl; | |
| cin >> year; | |
| // Sử dụng Quy tắc Doomsday với Doomsday của thể kỷ 21 là thứ 3 | |
| //Phần Finding a year's Doomsday (https://en.wikipedia.org/wiki/Doomsday_rule) | |
| int doomsday=3; // Thứ 3 | |
| a=(year%100)/12; | |
| b=(year%100)%12; | |
| c=b/4; | |
| doomsday = (a+b+c)%7+ doomsday; // Doomsday của năm hiện tại | |
| //===// | |
| // Xác định ngày mùng 1 của tháng vừa nhập vào thứ mấy | |
| //Phần Memorable dates that always land on Doomsday[edit] (https://en.wikipedia.org/wiki/Doomsday_rule) | |
| switch (month) | |
| { | |
| case 1: | |
| if ((year%100)%4==0) | |
| { | |
| doomsday = doomsday-4; | |
| temp1=31; | |
| } | |
| else | |
| { | |
| doomsday = doomsday-3; | |
| temp1=31; | |
| } | |
| break; | |
| case 2: | |
| if ((year%100)%4==0) | |
| { | |
| doomsday = doomsday-1; | |
| temp1=29; | |
| } | |
| else | |
| { | |
| doomsday = doomsday; | |
| temp1=28; | |
| } | |
| break; | |
| case 3: | |
| doomsday = doomsday; | |
| temp1=31; | |
| break; | |
| case 4: | |
| doomsday=doomsday+3; | |
| temp1=30; | |
| break; | |
| case 5: | |
| doomsday=doomsday-2; | |
| temp1=31; | |
| break; | |
| case 6: | |
| doomsday=doomsday+1; | |
| temp1=30; | |
| break; | |
| case 7: | |
| doomsday=doomsday+3; | |
| temp1=31; | |
| break; | |
| case 8: | |
| doomsday=doomsday-1; | |
| temp1=31; | |
| break; | |
| case 9: | |
| doomsday=doomsday+2; | |
| temp1=30; | |
| break; | |
| case 10: | |
| doomsday=doomsday-3; | |
| temp1=31; | |
| break; | |
| case 11: | |
| doomsday=doomsday; | |
| temp1=30; | |
| break; | |
| case 12: | |
| doomsday=doomsday+2; | |
| temp1=31; | |
| break; | |
| } | |
| if (doomsday>6) | |
| { | |
| doomsday = doomsday-7; | |
| } | |
| else if (doomsday<0) | |
| { | |
| doomsday = doomsday +7; | |
| } | |
| // Gán ngày mùng 1 vào phần tử trong mảng | |
| // Sau đó gán các giá trị sau đó đến ngày cuối cùng trong tháng | |
| arr[0][doomsday]=1; | |
| p1 = &arr[0][doomsday]; | |
| for(int row = 0; row < 6; row++) | |
| { | |
| for(int col = 0; col < 7; col++) | |
| { | |
| p1=p1+1; | |
| *p1=temp+1; | |
| temp=temp+1; | |
| if (arr[row][col]>temp1) | |
| { | |
| arr[row][col]=0; | |
| } | |
| } | |
| } | |
| for(int row = 0; row < 7; row++) | |
| { | |
| cout << "Thu" << row+1 << " "; | |
| } | |
| cout << endl; | |
| for(int row = 0; row < 6; row++) | |
| { | |
| for(int col = 0; col < 7; col++) | |
| { | |
| cout << right << setw(2) << setfill('0') << arr[row][col] << " "; | |
| } | |
| cout << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment