当前位置:网站首页>结果填空 星系炸弹(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;
}
边栏推荐
猜你喜欢

Idea uses dev tool to realize hot deployment

Delete specific elements in order table OJ

DOM--事件链、事件冒泡和捕获、事件代理

Canvas绘图1

Review of metallurgical physical chemistry -- Fundamentals of metallurgical reaction kinetics and characteristics of multiphase reaction kinetics

在线词云图生成(以WordArt为例)

ArcGIS之Model Builder

Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade

树莓派WIFI一键连接配置

对极大似然估计、梯度下降、线性回归、逻辑回归的理解
随机推荐
顺序表的增删查改
链表实现增删查改
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
排序之插入排序
shell运行原理
Use of IO streams
Microsoft Edge浏览器插件(1)
NRF51822 回顾总结
CAD-GIS数据转换
基于Highcharts平台的桑基图(Sankey diagram)绘制
es6新增--->对象(Object)
设置滚动条
【博学谷学习记录】超强总结,用心分享 | 集合
Oracle uses SQL to query the field information of a table (field type, length, etc.)
冶金物理化学复习 --- 气-液相反应动力学
DOM操作的案例
Openjudge: count the number of numeric characters
标准C语言总结4
Advanced multithreading: the role and implementation principle of volatile
Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade