fork download
  1. #include<cstring>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int date,month,year,t,n1,n,a,b,b1,c,a1,c1,d1,total,ad,dd,i;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int ans=0;
  11. int l=0;
  12. int hint=0;
  13. int temp=0;
  14. cin>>date>>month>>year;
  15. n=year%100;
  16. n1=n;
  17. a=n/12;
  18. a1=a;
  19. b=n1-(12*a);
  20. b1=b;
  21. c=b/4;
  22. c1=c;
  23. if((year>=2000&&year<=2099)||(year>=2400&&year<=2499)||(year>=2800&&year<=2899))
  24. d1=2;
  25. else if((year>=2100&&year<=2199)||(year>=2500&&year<=2599)||(year>=2900&&year<=2999))
  26. d1=0;
  27. else if((year>=2200&&year<=2299)||(year>=2600&&year<=2699)||(year>=3000&&year<=3099))
  28. d1=5;
  29. else
  30. d1=3;
  31.  
  32. total=a1+b1+c1+d1;
  33. if(total>=7)
  34. ad=total-7;
  35. else
  36. ad=total;
  37.  
  38. if(year%4==0)
  39. {
  40. if(year%100==0)
  41. {
  42. if(year%400==0)
  43. l=1;
  44. else
  45. l=0;
  46. }
  47. else
  48. l=1;
  49. }
  50. else
  51. l=0;
  52.  
  53. if(month==1&&l==1)
  54. dd=4;
  55. else if(month==1&&l==0)
  56. dd=3;
  57. else if(month==2&&l==1)
  58. dd=29;
  59. else if(month==2&&l==0)
  60. dd=28;
  61. else if(month==4)
  62. dd=4;
  63. else if(month==5)
  64. dd=9;
  65. else if(month==6)
  66. dd=6;
  67. else if(month==7)
  68. dd=11;
  69. else if(month==8)
  70. dd=8;
  71. else if(month==9)
  72. dd=5;
  73. else if(month==10)
  74. dd=10;
  75. if(month==11)
  76. dd=7;
  77. if(month==12)
  78. dd=12;
  79. if(dd<=date)
  80. {
  81. while(dd<=date)
  82. {
  83. temp=dd;
  84. dd=dd+7;
  85. }
  86. hint=date-temp;
  87. ans=hint+ad;
  88. if(ans>=7)
  89.  
  90. ans=ans-7;
  91. else
  92. ans=ans;
  93. }
  94. else
  95. {
  96. while(dd>=date)
  97. {
  98. temp=dd;
  99. dd=dd-7;
  100. }
  101. hint=temp-date;
  102. if(total>hint)
  103. ans=total-hint;
  104. else
  105. ans=hint-total;
  106. if(ans>=7)
  107. ans=ans-7;
  108. else
  109. ans=ans;
  110. }
  111. switch(ans)
  112. {
  113. case 0:{
  114. cout<<"Sunday"<<endl;
  115. break;
  116. }
  117. case 1:{
  118. cout<<"Monday"<<endl;
  119. break;
  120. }
  121. case 2:{
  122. cout<<"Tuesday"<<endl;
  123. break;
  124. }
  125. case 3:{
  126. cout<<"Wednesday"<<endl;
  127. break;
  128. }
  129. case 4:{
  130. cout<<"Thursday"<<endl;
  131. break;
  132. }
  133. case 5:{
  134. cout<<"Friday"<<endl;
  135. break;
  136. }
  137. case 6:{
  138. cout<<"Saturday"<<endl;
  139. break;
  140. }
  141.  
  142. }
  143. }
  144. return 0;
  145. }
Success #stdin #stdout 0s 3100KB
stdin
3
27 1 2015
7 7 2017
12 6 2015
stdout
Tuesday

Friday

Friday