c++ 時間相關的類型
阿新 • • 發佈:2019-04-25
cin 圖片 ring rar www ota 技術分享 total ble
給出一個時間S,我們想知道S距離2050年1月1日0點0時0分多少秒。
因為答案可能很大,請輸出答案模100的值。
對於每組數據,一行一個字符串表示時間。
時間格式為:YYYY-MM-DD HH:MM:SS,分別表示年、月、日、時,分、秒。
輸入的時間保證都在2019年1月1日以後(包含當天)。
關於時間轉換可以參考以下博客:
https://www.jianshu.com/p/80de04b41c31
https://www.cnblogs.com/qicosmos/p/3642712.html
https://blog.csdn.net/wizardtoh/article/details/81738682
https://blog.csdn.net/hou8389846/article/details/77962343
get_time put_time相關
https://blog.csdn.net/wangjieest/article/details/7761051
https://www.yiibai.com/cpp_standard_library/cpp_get_time.html
time_point 相關
https://www.xuebuyuan.com/716692.html?mobile=1
hdu 6491
時間間隔
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 153 Accepted Submission(s): 96
給出一個時間S,我們想知道S距離2050年1月1日0點0時0分多少秒。
因為答案可能很大,請輸出答案模100的值。
Input 第一行一個正整數 T (1≤T≤100000) 表示數據組數。
對於每組數據,一行一個字符串表示時間。
時間格式為:YYYY-MM-DD HH:MM:SS,分別表示年、月、日、時,分、秒。
輸入的時間保證都在2019年1月1日以後(包含當天)。
Output 對於每組數據輸出一行一個整數表示答案。
Sample Input 1 2019-01-01 00:00:00
Sample Output 0
#include<bits/stdc++.h> usingView Codenamespace std; int main() { string s; stringstream ss; s = "2050-01-01 00:00:00"; ss << s; tm beg ; ss >> get_time(&beg,"%Y-%m-%d"); ss >> get_time(&beg,"%H:%M:%S"); auto next_time = chrono::system_clock::from_time_t(time_t(mktime(&beg))); int n; cin>>n; while(n--) { tm ed; cin >> get_time(&ed,"%Y-%m-%d"); cin >> get_time(&ed,"%H:%M:%S"); auto from_time = chrono::system_clock::from_time_t(time_t(mktime(&ed))); auto diff = next_time - from_time ; cout<<abs(chrono::duration_cast<chrono::seconds>(diff).count())%100<<endl; } return 0; }
c++ 時間相關的類型