当前位置:网站首页>PTA 计算天数
PTA 计算天数
2022-08-09 10:58:00 【拾荒大妈】
本题要求编写程序计算某年某月某日是该年中的第几天。
输入格式:
输入在一行中按照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。闰年的2月有29天。
输出格式:
在一行输出日期是该年中的第几天。
输入样例1:
2009/03/02
输出样例1:
61
输入样例2:
2000/03/02
输出样例2:
62
思路:
根据每年小于等于7的月份中,偶月份为30天,奇月份每月31天,2月份除外,2月份闰年29天,非闰年28天;大于7的月份中,偶月份为31天,奇月份每月为30天
#include<stdio.h>
int main()
{
int year,month,day;
scanf("%d/%d/%d",&year,&month,&day);
int sign=0;//判断是否为闰年
int sum=0;
if((year%4==0&&year%100!=0)||year%400==0)
sign=1;
int i=1;
while(i<month)
{
if(i<=7)//小于等于7的偶月份每月30天,奇月份31天
{
if(sign==1&&i==2)//闰年2月份天数加上29
sum=sum+29;
else if(sign==0&&i==2)//非闰年2月份天数加上28
sum=sum+28;
else
{
if(i%2==1)
sum=sum+31;
else
sum=sum+30;
}
}
else//大于7的偶月份的每月31天,偶月份每月30天
{
if(i%2==1)
sum=sum+30;
else
sum=sum+31;
}
i++;
}
printf("%d",sum+day);
return 0;
}
`
边栏推荐
- PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
- 性能测试(01)-jmeter元件-线程组、调试取样器
- caffe ---make all编辑出错
- 备战金三银四:如何成功拿到阿里offer(经历+面试题+如何准备)
- The complete grammar of CSDN's markdown editor
- cesium加载地图
- 程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
- TensorFlow:NameError: name ‘input_data’ is not defined
- TensorFlow: NameError: name 'input_data' is not defined
- Tensorflow realize parameter adjustment of linear equations
猜你喜欢
随机推荐
Solve 1. tensorflow runs using CPU but not GPU 2. GPU version number in tensorflow environment 3. Correspondence between tensorflow and cuda and cudnn versions 4. Check cuda and cudnn versions
中断系统结构及中断控制
去除蜂窝状的噪声(matlab实现)
性能测试(01)-jmeter元件-线程组、调试取样器
GOPROXY 中国代理
golang源代码阅读,sync系列-Cond
The complete grammar of CSDN's markdown editor
uni-app 自带的picker封装一个日期-时间选择器
备份mongodb数据库(认证)
情感分析SowNLP词库
Since I use the HiFlow scene connector, I don't have to worry about becoming a "dropper" anymore
MATLAB代码实现三次样条插值
MNIST机器学习入门
性能测试(03)-JDBC Request
我用开天平台做了一个定时发送天气预报系统【开天aPaaS大作战】
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
CSDN的markdown编辑器语法完整大全
Unix Environment Programming Chapter 15 15.7 Message Queuing
activemq 消息持久化
kubernetes中不可见的OOM