码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-1154 Ordinal Number Of Date(一年中的第几天)

时间:2019-08-11 12:45:37      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:lse   def   bool   int   number   ret   ==   签到   div   

签到题 ,随便写写

 1 int rn[] = {31,29,31,30,31,30,31,31,30,31,30,31};
 2 int frn[] = {31,28,31,30,31,30,31,31,30,31,30,31};
 3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 4 class Solution
 5 {
 6     public:
 7         
 8         bool isrun(int year)
 9         {
10             return year % 4 == 0 && year %100 != 0 ||year % 400 == 0;
11         }
12         int ordinalOfDate(string date)
13         {
14             int k1 = 0,k2 = 0,k3 = 0;
15             k1 = (date[0]-0)*1000+(date[1]-0)*100+(date[2]-0)*10+(date[3]-0);
16             k2 = (date[5]-0)*10+(date[6]-0);
17             k3 = (date[8]-0)*10+(date[9]-0);
18             int rnt = 0;
19             if(isrun(k1))
20             {
21                 _for(i,0,k2-1)
22                     rnt += rn[i];
23                 rnt += k3;
24             }
25             else
26             {
27                 _for(i,0,k2-1)
28                     rnt += frn[i];
29                 rnt += k3;
30             }
31             return rnt;
32         }
33 };

 

Leetcode-1154 Ordinal Number Of Date(一年中的第几天)

标签:lse   def   bool   int   number   ret   ==   签到   div   

原文地址:https://www.cnblogs.com/Asurudo/p/11334529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!