日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 153d(日期转换)特殊题目

發布時間:2023/12/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 153d(日期转换)特殊题目 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

date change

You are given a date in “DD.MM.YYYY” (“day.month.year”) format and a number of days shift you have to add to this date. Output the resulting date.

Input
The first line of input contains the date in “DD.MM.YYYY” format: two digits for day (with leading zero if needed), dot, two digits for month (with leading zero if needed), dot, four digits for year. The notation is guaranteed to give a valid date between 1980 and 2020, inclusive.

The second line contains an integer shift (?-?1000?≤?shift?≤?1000).

Output
Output a date equal to the given one + shift days, in the same format “DD.MM.YYYY”.

Examples
Input
10.02.2012
12
Output
22.02.2012
Input
01.02.2010
-40
Output
23.12.2009
Input
01.01.2000
365
Output
31.12.2000
Input
13.08.1990
-609
Output
12.12.1988
Note
When manipulating the dates, take into account leap years; don’t care about time zones/daylight saving time.
題意好理解,給你一個時期,然后給你一個數,在這個日期上加上或者減去一個數,求最后的日期是多少。問題沒有什么技術含量,但是有很多要考慮的。閏年二月與平年二月,在減去某個數時相應的月份與年份的變化。題目不難,細節處理好就可以了。(一天就寫了一道題,阿西吧。在床上躺了一天了)。
代碼給上:

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std;int d,m,y; int nd; char a,b; int md[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};//把除了二月之外的每個月的天數保存到數組里。int main() {while(scanf("%2d%c%2d%c%4d",&d,&a,&m,&b,&y)!=EOF){int x;scanf("%d",&nd);if(nd>=0)//增加某個數字{while(nd){if(m==02)//二月應該特判啦{if(y%4) x=28;else x=29;}else x=md[m];d++;if(d>x) {d=1;m++;if(m>12) {y++;m=1;}}nd--;}printf("%.2d%c%.2d%c%.4d\n",d,a,m,b,y);}else{while(nd<0)//減去一個數字{d--;if(d<1)//d=0的時候表示應該減一個月份了。{if(m==1) //如果當前月份為一月的話,減完之后應該就是去年的十二月了{m=12;y--;x=md[m];}else if(m==3)//如果是三月的話,減完之后是二月,特判,嚶嚶嚶。{if((y%4)) x=28;else x=29;m=2;}else//其余的就直接寫就可以了啊。{m--;x=md[m];}d=x;}nd++;}printf("%.2d%c%.2d%c%.4d\n",d,a,m,b,y);}}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的codeforces 153d(日期转换)特殊题目的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。