csansoon

P4.09 P18777 Day of the week

Oct 24th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string day_of_the_week (int d, int m, int y){
  5.     int c,a,f;
  6.     m=m-2;
  7.     if (m<=0) {
  8.         m=m+12;
  9.         --y;}
  10.     c=(y/100);
  11.     a=(y%100);
  12.     f = ((2.6 * m) - 0.2);
  13.         f= f + d + a + (a / 4) + (c / 4) - (2 * c);
  14.         while (f < 0) f = f + 7;
  15.         f = f%7;
  16.     while (f < 0) f += 7;
  17.     f = f%7;
  18.     switch (f) {
  19.         case 0:
  20.             return "Sunday";
  21.             break;
  22.         case 1:
  23.             return "Monday";
  24.             break;
  25.         case 2:
  26.             return "Tuesday";
  27.             break;
  28.         case 3:
  29.             return "Wednesday";
  30.             break;
  31.         case 4:
  32.             return "Thursday";
  33.             break;
  34.         case 5:
  35.             return "Friday";
  36.             break;
  37.         case 6:
  38.             return "Saturday";
  39.             break;
  40.         default:
  41.             return "wtf";
  42.             break;
  43.         }
  44. }
  45.    
  46.    
  47. int main(){
  48.     int d, m, y;
  49.     cin >>d>>m>>y;
  50.     cout<<day_of_the_week(d,m,y)<<endl;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment