标签: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