当前位置:网站首页>1154. day of the year
1154. day of the year
2022-06-13 06:40:00 【Mr Gao】
1154. The day of the year
Give you a string date , Press YYYY-MM-DD Format represents a The current chronology date . Returns the day of the current year .
Example 1:
Input :date = “2019-01-09”
Output :9
explain : The given date is 2019 The ninth day of the year .
Example 2:
Input :date = “2019-02-10”
Output :41
There is no difficulty in this problem , Just do it as usual , Pay attention to the judgment conditions for leap years . The solution code is as follows :
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;
}
边栏推荐
- DataGridView data export to excel (in case of small amount of data)
- The jadx decompiler can decompile jars and apks
- Overview of demoplayer program framework design of ijkplayer
- 无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
- 《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
- Thread correlation point
- [FAQs for novices on the road] understand program design step by step
- MFS詳解(七)——MFS客戶端與web監控安裝配置
- 時間格式化工具----moment.js(網頁時間實時展示)
- The web server failed to start Port 7001 was already in use
猜你喜欢
In kotlin?,!,?:,:, - & gt;、== Brief description of symbols
Analysis of 43 cases of MATLAB neural network: Chapter 11 optimization of continuous Hopfield Neural Network -- optimization calculation of traveling salesman problem
[FAQs for novices on the road] understand program design step by step
Jetpack - basic use of room
Notes on wechat applet development
Dragon Boat Festival wellbeing, use blessing words to generate word cloud
RFID process management solution for electroplating fixture
Base64 principle
Common method of props changing value V-model sync
JetPack - - - DataBinding
随机推荐
Custom view subtotal
Why does TCP establish three handshakes and four waves
Unable to find method 'org gradle. api. artifacts. result. ComponentSelectionReason. getDesc
数据在内存中的存储(C语言)
MFS详解(七)——MFS客户端与web监控安装配置
vue3路由缓存组件状态以及设置转场动画
Two uses of bottomsheetbehavior
Array operations in JS
Hidden and wx:if
JNI's bitmap grayscale image (rgba_8888 and rgb_565)
Dart class inherits and implements mixed operators
Introduction to applet layout
Command line for database
MFS explanation (V) -- MFS metadata log server installation and configuration
Recent problems
RN Metro packaging process and sentry code monitoring
RFID process management solution for electroplating fixture
Vector control of Brushless DC motor (4): sensorless control based on sliding mode observer
App performance test: (II) CPU
[FAQs for novices on the road] understand program design step by step