ZJUTACM上面1863求日期问题
今天星期几
Time Limit:1000MS Memory Limit:32768KDescription:
笨笨的chen_h,一天到晚忘记今天是星期几?所以他想让你帮他写一个程序,只要输入日期,就能回答是星期几。Input:
一些日期,日期以年、月、日表示。年、月、日为三个正整数,互相以空格隔开。Output:
对每个日期输出一个大写开头的英文单词,以表示星期几(Monday,Tuesday, Wednesday,Thursday,Friday,Saturday,Sunday分别表示星期一到星期天)。Sample Input:
1 1 1 2 1 1 2006 7 10Sample Output:
Monday Tuesday Monday
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int y, m, d; 6 string xingqi[7] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" }; 7 while (cin >> y >> m >> d) 8 { 9 if (m == 1 || m == 2) 10 { 11 m += 12; 12 y--; 13 } 14 int w = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7; 15 cout << xingqi[w]<<endl; 16 } 17 }