close
原文
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3170
感謝Ruby兔大大的翻譯
http://rubyacm.blogspot.com/2011/08/12019-dooms-day-algorithm.html
C++
#include <iostream> using namespace std; int main() { int c,m,d; cin>>c;//輸入測資數量 while(c--) { cin>>m>>d;//輸入月份日期 for(int i =m-1;i>=1;i--)//將月份日期換成天數 { //i代表之前的月份 if(i==2)//2月 { d=d+28; } else if(i%2==0)//偶數月 { if(i>=8)//八月之後 { d=d+31; } else//八月以前 { d=d+30; } } else if(i%2==1)//奇數月 { if(i>=8)//八月後 { d=d+30; } else//八月前 { d=d+31; } } } if(d%7==1)//2011年第一天是星期六 { cout<<"Saturday"<<endl; } else if(d%7==2) { cout<<"Sunday"<<endl; } else if(d%7==3) { cout<<"Monday"<<endl; } else if(d%7==4) { cout<<"Tuesday"<<endl; } else if(d%7==5) { cout<<"Wednesday"<<endl; } else if(d%7==6) { cout<<"Thursday"<<endl; } else if(d%7==0) { cout<<"Friday"<<endl; } } return 0; }
文章標籤
全站熱搜