当前位置:网站首页>1154. 一年中的第几天
1154. 一年中的第几天
2022-06-13 06:20:00 【Mr Gao】
1154. 一年中的第几天
给你一个字符串 date ,按 YYYY-MM-DD 格式表示一个 现行公元纪年法 日期。返回该日期是当年的第几天。
示例 1:
输入:date = “2019-01-09”
输出:9
解释:给定日期是2019年的第九天。
示例 2:
输入:date = “2019-02-10”
输出:41
这题没什么难度,常规去做就行了,注意下闰年判断条件。解题代码如下:
int dayOfYear(char * date){
int year=0;
int month=0;
int day=0;
int target_day=0;
int i;
int num=0;
int months[12]={
31,28,31,30,31,30,31,31,30,31,30,31};
i=0;
while(date[i]!='\0'){
if(date[i]=='-'){
num++;
i++;
continue;
}
else{
if(num==0){
year=year*10+date[i]-'0';
}
if(num==1){
month=month*10+date[i]-'0';
}
if(num==2){
day=day*10+date[i]-'0';
}
}
i++;
}
if((year%4==0&&year%100!=0)||year%400==0){
months[1]=29;
}
for(i=0;i<month-1;i++){
target_day=target_day+months[i];
}
target_day=target_day+day;
return target_day;
}
边栏推荐
- MFS explanation (V) -- MFS metadata log server installation and configuration
- RN Metro packaging process and sentry code monitoring
- Ijkplayer compilation process record
- In kotlin?,!,?:,:, - & gt;、== Brief description of symbols
- 欧姆龙平替国产大货—JY-V640半导体晶元盒读写器
- [SketchUp 2021] CAD file import and modeling in the sketch master (establish elevation model in the sketch master by using CAD drawings), and the sketch master exports 2D, 3D and elevation effects of
- Super model logo online design and production tool
- Analysis of synchronized
- Usegeneratedkeys=true configuration
- Simple use of event bus
猜你喜欢
RN Metro packaging process and sentry code monitoring
MFS explanation (VI) -- MFS chunk server installation and configuration
JVM Foundation
[virtual machine] VMware virtual machine occupies too much space. Solution
【sketchup 2021】草图大师的图像输出与渲染之样式说明【边线设置、平面设置、背景设置、水印设置、建模设置、天空背景创建天空、利用水印背景创建天空(重要)】
Analysis of 43 cases of MATLAB neural network: Chapter 10 classification of discrete Hopfield Neural Network -- evaluation of scientific research ability of colleges and Universities
Kotlin collaboration channel
Kotlin collaboration -- context and exception handling
机器学习笔记 - 监督学习备忘清单
Machine learning notes - supervised learning memo list
随机推荐
DataGridView data export to excel (in case of small amount of data)
Analyzing server problems using jvisualvm
‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
The jadx decompiler can decompile jars and apks
《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
Relationship between fragment lifecycle and activity
【sketchup 2021】草图大师的图像输出与渲染之样式说明【边线设置、平面设置、背景设置、水印设置、建模设置、天空背景创建天空、利用水印背景创建天空(重要)】
【虚拟机】 VMware虚拟机占用空间过大解决
synchronized浅析
時間格式化工具----moment.js(網頁時間實時展示)
Win10 drqa installation
BlockingQueue源码
JetPack - - - DataBinding
端午安康,使用祝福话语生成词云吧
[kernel] two methods of driver compilation: compiling into modules and compiling into the kernel (using miscellaneous device driver templates)
Session and browser
Simple use of event bus
Detailed explanation of the player startup process of ijkplayer code walk through
数据在内存中的存储(C语言)
[JS] handwriting call(), apply(), bind()