結果
問題 | No.721 Die tertia (ディエ・テルツィア) |
ユーザー |
![]() |
提出日時 | 2020-07-25 16:35:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,017 bytes |
コンパイル時間 | 808 ms |
コンパイル使用メモリ | 95,196 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 08:27:38 |
合計ジャッジ時間 | 1,590 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function 'int lastDayOfMonth(int, int)': main.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type] 55 | } | ^
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <iomanip>#include <stack>#include <algorithm>#include <string>#include <map>#include <iterator>#include <set>#include <queue>using namespace std;int lastDayOfMonth(int year, int month) {if (month == 2) {if (year % 400 == 0) {return 29;} else if (year % 100 == 0) {return 28;} else if (year % 4 == 0) {return 29;} else {return 28;}} else {switch (month) {case 1:return 31;case 3:return 31;case 4:return 30;case 5:return 31;case 6:return 30;case 7:return 31;case 8:return 31;case 9:return 30;case 10:return 31;case 11:return 30;case 12:return 31;}}}int extract(string s) {if (s[0] == '0') {return s[1] - '0';} else {return stoi(s);}}string insert(int n) {string s;if (n <= 9) {s += '0';s += to_string(n);return s;} else {return to_string(n);}}int main() {string s;cin >> s;int YYYY = extract(s.substr(0, 4));int MM = extract(s.substr(5, 2));int DD = extract(s.substr(8, 2));int targetDay = DD + 2;string result;if (targetDay <= lastDayOfMonth(YYYY, MM)) {} else {targetDay = targetDay - lastDayOfMonth(YYYY, MM);if (MM == 12) {MM = 1;YYYY += 1;} else {MM += 1;}}result += insert(YYYY);result += "/";result += insert(MM);result += "/";result += insert(targetDay);cout << result << endl;return 0;}