当前位置:网站首页>OpenJudge NOI 1.13 18:Tomorrow never knows?
OpenJudge NOI 1.13 18:Tomorrow never knows?
2022-06-11 02:04:00 【君义_noip】
【题目链接】
OpenJudge NOI 1.13 18:Tomorrow never knows?
【题目考点】
1. 模拟
【解题思路】
模拟日期值的变化
要计算当前日期的下一天,先将“日”增加1,
如果“日”的值超过了当前月份的天数,那么月份增加1,“日”变为1。
如果月份的值增加1后超过了12,那么年份增加1,月份变为1。
这里需要设两个函数
isLeap函数判断某一年是否为闰年,能整除400或不能整除100但能整除4的年份为闰年。
getMonthDay求某一年某月份的天数,这里会考虑闰年的影响。
【题解代码】
解法1:
#include<bits/stdc++.h>
using namespace std;
bool isLeap(int y)
{
return y%400 == 0 || y%100 != 0 && y%4 == 0;
}
int getMonthDay(int y, int m)
{
if(m == 2)
{
if(isLeap(y))
return 29;
else
return 28;
}
else if(m == 4 || m == 6 || m == 9 || m == 11)
return 30;
else
return 31;
}
int main()
{
int y, m, d;
scanf("%d-%d-%d", &y, &m, &d);
d++;
if(d > getMonthDay(y, m))
{
d = 1;
m++;
if(m > 12)
{
y++;
m = 1;
}
}
printf("%d-%02d-%02d", y, m, d);
return 0;
}
边栏推荐
- error exepected identifier before ‘(‘ token, grpc 枚举类编译错误
- net core天马行空系列-可用于依赖注入的,数据库表和c#实体类互相转换的接口实现
- Jetpack Compose Box控件
- 码农的进阶之路 | 每日趣闻
- Unity determines whether the object is in the camera field of view
- Forest v1.5.22 发布!支持Kotlin
- Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether
- CPT 102_LEC 17
- 扁平数据转tree与tree数据扁平化
- Les produits financiers de l'assurance - rente peuvent - ils être composés? Quel est le taux d'intérêt?
猜你喜欢

Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)

helm 部署traefik ingress

Koa2 learning notes

【斐波那契数列】

Uni app - one click access to user information

Why is the trend chart of precious metal silver strong?
![[Fibonacci series]](/img/03/70b1363e91142a8600d97c59b01b0f.png)
[Fibonacci series]
![[resolved] how to fix another update in progress WordPress upgrade error](/img/b1/7b9945c1a623c20288f0d232cbb0c4.jpg)
[resolved] how to fix another update in progress WordPress upgrade error

The Google search console webmaster tool cannot read the sitemap?

Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)
随机推荐
Jetpack Compose Scaffold和BottomAppBar(底部导航)
P4338 [ZJOI2018]历史(树剖)(暴力)
Setting access to win10 shared folder without verification
动态给对象添加属性
Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
SQL | 计算总和
List 过滤、排序、校验等处理方法
Mentality cannot collapse
弄懂了采矿业与碳中和的逻辑,就读懂了矿区无人驾驶的千亿市场
【面试题 17.04. 消失的数字】
Navicat Premium 15 工具自动被杀毒防护软件删除解决方法
10007. ISBN number
STC8A8K64D4 EEPROM读写失败
What is ttfb
92. CompletableFuture 实战
What do you know about the set class? Soul questions from Volume I
Forest v1.5.22 发布!支持Kotlin
牛客网:数组中只出现一次的两个数字
1031. maximum sum of two non overlapping subarrays
Three special data types, day3 and redis (geographic location, cardinality statistics and bitmap scene usage)