当前位置:网站首页>结果填空 星系炸弹(Excel秒杀)
结果填空 星系炸弹(Excel秒杀)
2022-07-28 05:19:00 【小白鼠零号】
在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。
每个炸弹都可以设定多少天之后爆炸。
比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。
有一个贝塔炸弹,2014年11月9日放置,定时为1000天,请你计算它爆炸的准确日期。
请填写该日期,格式为 yyyy-mm-dd 即4位年份2位月份2位日期。比如:2015-02-19
请严格按照格式书写。不能出现其它文字或符号。
答案
2017-08-05
Excel方法



解题过程
我采用天数累加判断的方法,比较稳。
用两个数组分别存储闰年和非闰年的每月天数,在天数累加的过程中,判断是否超过但前月份的天数,若超过则月份+1,天数置为一。同时判断月份+1后是否超过最大的12月份,超过就年份加一。
闰年:能被4整除但不能被100整除 或者 能被100和400整除 的就是闰年。
附上代码
#include<iostream>
using namespace std;
int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int b[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
void FindDay(int,int,int,int);
FindDay(2014,11,9,1000);
return 0;
}
void FindDay(int y,int m,int d,int times)
{
while(times>0)
{
d++;
if((y%4==0&&y%100!=0)||(y%400==0))
{
if(d>b[m])
{
m++;
d=1;
}
if(m>12)
{
y++;
m=1;
}
}
else
{
if(d>a[m])
{
m++;
d=1;
}
if(m>12)
{
y++;
m=1;
}
}
times--;
}
cout<<y<<"-";
m>9?cout<<m<<"-":cout<<"0"<<m<<"-";
d>9?cout<<d<<endl:cout<<"0"<<d<<endl;
}
边栏推荐
- 函数基础知识以及特殊点
- 冶金物理化学复习 ---- 气固反应动力学
- A file upload tool website written by individuals
- Deep learning medical image model reproduction
- GIS领域竞赛整理(不完全统计)
- Oracle uses SQL to query the field information of a table (field type, length, etc.)
- Pytorch uses hook to get feature map
- C语言走迷宫
- 标准C语言学习总结7
- 对极大似然估计、梯度下降、线性回归、逻辑回归的理解
猜你喜欢

Advanced multithreading: the role and implementation principle of volatile

Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later

Zotero——一款文献管理工具

冶金物理化学复习 ---- 气固反应动力学

Event_looop-事件循环机制

Microsoft Edge浏览器插件(1)

shell运行原理

环形链表问题

【uni-app】uni-app中scroll-into-view的使用

Custom JSON return data
随机推荐
Review of metallurgical physical chemistry -- cathodic polarization, overpotential, anode and anode process in metal electrodeposition
C语言回顾(字节对齐篇)
ArcMap中的距离工具条(Distance)
冶金物理化学复习 ---- 气固反应动力学
DOM——事件
Oracle view lock table statement and unlocking method
c语言:通过一个例子来认识函数栈帧的创建和销毁讲解
Custom JSON return data
GD32F407 移植FreeRTOS+Lwip
Learning of image enhancement evaluation index -- structural similarity SSIM
标准C语言总结4
media-搭建直播服务器
How Visio can quickly generate the same pattern and image matrix
Pytorch uses maxpool to realize image expansion and corrosion
Openjudge: filter extra spaces
Interface idempotency problem
Arcgis Engine安装的若干问题
Writing methods of scientific research papers: add analysis and discussion in the method part to explain their contributions and differences
Merge two ordered arrays of order table OJ
【博学谷学习记录】超强总结,用心分享 | 集合