当前位置:网站首页>日期类(暑假每日一题 19)
日期类(暑假每日一题 19)
2022-08-10 08:34:00 【sweetheart7-7】
编写一个日期类,要求按 xxxx-xx-xx
的格式输出日期,实现加一天的操作。
输入格式
第一行包含整数 T T T,表示共有 T T T 组测试数据。
每组数据占一行,包含 3 3 3 个用空格隔开的整数,分别表示年月日。
输出格式
每组数据输出一行,一个结果,按 xxxx-xx-xx
的格式输出,表示输入日期的后一天的日期。
数据范围
输入日期保证合法且不会出现闰年。
年份范围 [ 1000 , 3000 ] [1000,3000] [1000,3000]
输入样例:
2
1999 10 20
2001 1 31
输出样例:
1999-10-21
2001-02-01
#include<iostream>
using namespace std;
int md[] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void next_day(int& y, int &m, int &d){
d ++;
int days = md[m];
if((y % 400 == 0 || y % 100 != 0 && y % 4 == 0) && m == 2)
days++;
if(d > days) d %= days, m++;
if(m > 12) m %= 12, y++;
}
int main(){
int t;
cin >> t;
int y, m, d;
while(t--){
cin >> y >> m >> d;
next_day(y, m, d);
printf("%04d-%02d-%02d\n", y, m, d);
}
return 0;
}
边栏推荐
- 1499. 满足不等式的最大值 堆/双端队列
- The sixteenth day & the basic operation of charles
- Rust learning: 6.5_Array of composite types
- ARM结构体系3:ARM指令的寻址和异常中断处理
- js--------对象数组转换成二维数组(excel表格导出)
- dayjs-----time format
- ARM Architecture 3: Addressing and Exception Handling of ARM Instructions
- ARM Architecture 2: Processor Core and Assembly Instruction Set
- 2022-08-01 Advanced Network Engineering (23) Advanced VLAN Technology - VLAN Aggregation, MUX VLAN
- StringUtils的具体操作
猜你喜欢
详解构建mock服务最方便的神器——Moco
NaiveUI中看起来没啥用的组件(文字渐变)实现原来这么简单
iwemeta metaverse: a doll sells for 9999 yuan, and Bubble Mart thinks it is not expensive at all
物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
怎么使用【jmeter正则表达式提取器】解决返回值作参数的问题
PTA Exercise 2.2 Rotate an Array Left
Binary tree --- heap
iwemeta metaverse: Ali's first COO: how to build a sales force
本地生活商家如何通过短视频赛道,提升销量曝光量?
【OAuth2】二十、OAuth2扩展协议 PKCE
随机推荐
组合数模板
ABAP Data Types 和XSD Type 映射关系以及XSD Type属性
封装和使用通用的工具栏组件
NaiveUI中看起来没啥用的组件(文字渐变)实现原来这么简单
In the SQL SERVER database, if the data of the table is added, deleted, or modified, will the index of the table be recorded in the ldf log?
怎么使用【jmeter正则表达式提取器】解决返回值作参数的问题
raid5的写性能,是不的比raid10快一些?
同步锁synchronized追本溯源
编程老手如何在autojs和冰狐智能辅助之间选择?
The implementation of the seemingly useless component (text gradient) in NaiveUI is so simple
The precise effect of network integration promotion outsourcing in the era of Internet of Things-Shenzhen Win-Win World News
phpstudy starts automatically
DAY26:GetShell专题
Ask next CDC mysql to Doris. Don't show the specific number of lines, how to do?
ShardingSphere入门
VMware ESX Server常用命令行
Synchronization lock synchronized traces the source
js reads excel time format conversion
Compilation failure:找不到符号
js读取excel时间格式转换