碰到日期题就怕的我来写一道水题吧
生活随笔
收集整理的這篇文章主要介紹了
碰到日期题就怕的我来写一道水题吧
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
HDOJ-2005,
http://acm.hdu.edu.cn/showproblem.php?pid=2005
20XX系列的水題哈哈,寫了二十分鐘,就為找到一種比較正常不傻逼的寫法。。。
嗯,學(xué)習(xí)了一下,閏年的判斷可以寫成一個接受參數(shù)的宏。
#define lev(n) (n%4==0&&(n%100!=0||n%400==0))然后建立一個二維數(shù)組來存儲閏年和非閏年的每月天數(shù)。
int calendar[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31 } }然后 calendar[luv(year)][i] 就是i月的天數(shù)啦!
附2005AC代碼:
1 #include <stdio.h> 2 #include <math.h> 3 #define lev(n) (n%4==0&&(n%100!=0||n%400==0)) 4 5 int main() { 6 int calendar[2][13] = { 7 {0,31,28,31,30,31,30,31,31,30,31,30,31}, 8 {0,31,29,31,30,31,30,31,31,30,31,30,31 } 9 }; 10 int year, month, day; 11 int i, count; 12 while (~scanf("%d/%d/%d", &year, &month, &day)) { 13 for (i = 1, count = 0; i < month; i++) { 14 count += calendar[lev(year)][i]; 15 } 16 printf("%d\n", count+day); 17 } 18 }?
轉(zhuǎn)載于:https://www.cnblogs.com/ray-coding-in-rays/p/6196122.html
總結(jié)
以上是生活随笔為你收集整理的碰到日期题就怕的我来写一道水题吧的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: braintree php 开发,php
- 下一篇: Category 的一些事