HDU 2005

来源:互联网 发布:高速公路收费查询软件 编辑:程序博客网 时间:2024/05/22 06:05

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2005


题目大意:中文题


题目思路:判断是否为闰年,将月份总天数和当前天数相加。输入使用scanf()。


代码:

#include<stdio.h>bool ifrun(int x){    if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))return 1;    else return 0;}int main(){    int y, m, d;    int run[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };    int norun[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };    while (~scanf("%d/%d/%d", &y, &m, &d))    {        int sum = 0;        if (ifrun(y))        {            for (int i = 0; i < m - 1; i++)                sum += run[i];        }        else        for (int i = 0; i < m - 1; i++)            sum += norun[i];        printf("%d\n", sum + d);    }}


原创粉丝点击