HDU 2005 (水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2005
题目大意:给定年份,计算是第几天
题目大意:给定年份,计算是第几天
解题思路:
很水,判定下是否为闰年,方法:四年一闰,百年不闰,四百年再闰
②、世纪年能被400整除的是闰年。(如2000年是闰年,1900年不是闰年)
代码:
1 #include<iostream> 2 using namespace std; 3 int s[2][13] = {{0, 31, 29, 31, 30, 31, 30, 31, 31,30, 31, 30, 31},//闰 4 {0, 31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31} 5 }; 6 int main() 7 { 8 int p; 9 char c; 10 int sum; 11 int year, month, day; 12 while(cin >> year >> c >> month >> c >> day) 13 { 14 p = 1; 15 sum = 0; 16 if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) 17 p = 0; 18 for(int i = 0; i < month; i ++) 19 sum += s[p][i]; 20 sum += day; 21 cout << sum << endl; 22 } 23 }