# 第几天 y年m月d日是哪一年的第几天。 比如y年的1月1日是那一年的第一天,那么y年m月d日是哪一年的第几天。 #### 输入 ``` y m d ``` #### 输出 输出一个整数 ### 样例 #### 输入 ``` 2000 7 7 ``` #### 输出 ``` 189 ``` ## aop ### before ```cpp #include using namespace std; bool is_leap(int year) { return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; } ``` ### after ```cpp ``` ## 答案 ```cpp int main() { int y, m, d, ans = 0; cin >> y >> m >> d; int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (is_leap(y)) //判断闰年 { for (int i = 0; i < (m - 1); i++) //记录1-(m-1)月天数 { ans += L_m_d[i]; } ans += d; } else { for (int i = 0; i < (m - 1); i++) { ans += nonL_m_d[i]; } ans += d; } cout << ans << endl; return 0; } ``` ## 选项 ### A ```cpp int main() { int y, m, d, ans = 0; cin >> y >> m >> d; int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (is_leap(y)) //判断闰年 { for (int i = 0; i < m; i++) //记录1-(m-1)月天数 { ans += L_m_d[i]; } ans += d; } else { for (int i = 0; i < (m - 1); i++) { ans += nonL_m_d[i]; } ans += d; } cout << ans << endl; return 0; } ``` ### B ```cpp int main() { int y, m, d, ans = 0; cin >> y >> m >> d; int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (is_leap(y)) //判断闰年 { for (int i = 0; i < (m - 1); i++) //记录1-(m-1)月天数 { ans += L_m_d[i]; } ans += d; } else { for (int i = 0; i < m; i++) { ans += nonL_m_d[i]; } ans += d; } cout << ans << endl; return 0; } ``` ### C ```cpp int main() { int y, m, d, ans = 0; cin >> y >> m >> d; int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (is_leap(y)) //判断闰年 { for (int i = 0; i < m; i++) //记录1-(m-1)月天数 { ans += L_m_d[i]; } ans += d; } else { for (int i = 0; i < m; i++) { ans += nonL_m_d[i]; } ans += d; } cout << ans << endl; return 0; } ```