Advertisement
informaticage

Weekdays

Jun 25th, 2022
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. const int offset[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  4.  
  5. const std::string daynames[] = {
  6.   "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  7. };
  8.  
  9. int main () {
  10.   int day, month, year;
  11.   std::cin >> day >> month >> year;
  12.   year -= month < 3;
  13.   int weekday = (year + year/4 - year/100 + year/400 + offset[month-1] + day) % 7;
  14.  
  15.   std::cout << "Day: " << daynames[weekday];
  16.   return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement