当前位置:网站首页>CCF 201509-2 日期计算
CCF 201509-2 日期计算
2022-07-25 09:23:00 【Tobi_Obito】
题目
问题描述
给定一个年份y和一个整数d,问这一年的第d天是几月几日?
注意闰年的2月有29天。满足下面条件之一的是闰年:
1) 年份是4的整数倍,而且不是100的整数倍;
2) 年份是400的整数倍。
输入格式
输入的第一行包含一个整数y,表示年份,年份在1900到2015之间(包含1900和2015)。
输入的第二行包含一个整数d,d在1至365之间。
输出格式
输出两行,每行一个整数,分别表示答案的月份和日期。
样例输入
2015
80
样例输出
3
21
样例输入
2000
40
样例输出
2
9
问题分析
一道基础的日期类型题目,直接上代码。
代码
#include<cstdio>
using namespace std;
int AbnormalYear(int year){
if((year % 4 == 0 && year % 100!=0) || year % 400 == 0)
return 1;
return 0;
}
int main(){
int year,day,i,t;
int month[2][13];//[1][x]-闰年 [0][x]-非闰年
month[0][1] = month[1][1] = 0;
month[0][2] = month[1][2] = 31;
month[0][3] = 59;
month[0][4] = 90;
month[0][5] = 120;
month[0][6] = 151;
month[0][7] = 181;
month[0][8] = 212;
month[0][9] = 243;
month[0][10] = 273;
month[0][11] = 304;
month[0][12] = 334;
for(int i=3;i<=12;i++)
month[1][i] = month[0][i] + 1;
scanf("%d %d",&year,&day);
t = AbnormalYear(year);
for(i=12;month[t][i] >= day;i--);
printf("%d\n%d\n",i,day-month[t][i]);
return 0;
}
边栏推荐
- 【深度学习】卷积神经网络
- 数据分析面试记录1-5
- pytorch使用tensorboard实现可视化总结
- 深入理解pytorch分布式并行处理工具DDP——从工程实战中的bug说起
- Get to know opencv4.x for the first time --- add Gaussian noise to the image
- Wechat applet realizes the rotation map (automatic switching & manual switching)
- 初识Opencv4.X----图像直方图匹配
- Surfaceview flash screen (black problem)
- Voice chat app source code - produced by NASS network source code
- 预测2021年:加速实现RPA以外的超自动化成果
猜你喜欢

Get to know opencv4.x for the first time --- add salt and pepper noise to the image

初识Opencv4.X----ROI截取

无向连通图邻接矩阵的创建输出广度深度遍历

pytorch使用tensorboard实现可视化总结

Definition of cell

目标检测与分割之MaskRCNN代码结构流程全面梳理+总结

服务器cuda toolkit多版本切换

First knowledge of opencv4.x --- image histogram equalization

预测2021年:加速实现RPA以外的超自动化成果

@3-1 CCF 2020-09-1 scale detection point query
随机推荐
OC -- Foundation -- array
初识Opencv4.X----图像模板匹配
matlab绘图|坐标轴axis的一些常用设置
初识Opencv4.X----方框滤波
Dream set sail (the first blog)
MLOps专栏介绍
AI模型风险评估 第1部分:动机
从鱼眼到环视到多任务王炸——盘点Valeo视觉深度估计经典文章(从FisheyeDistanceNet到OmniDet)(上)
Get to know opencv4.x for the first time --- add Gaussian noise to the image
【数据挖掘】第三章 数据分析基础
pytorch使用tensorboard实现可视化总结
@3-1 CCF 2020-09-1 scale detection point query
基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(上)
目标检测与分割之MaskRCNN代码结构流程全面梳理+总结
CDA LEVELⅠ2021新版模拟题二(附答案)
expect+sh实现自动交互
@1-1 CCF 2021-04-1 gray histogram
[code source] I have a big head for a problem every day
[code source] daily one question three paragraph
Surfaceview flash screen (black problem)