1234567891011121314151617181920212223242526272829303132 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: zhuyijun
- * @Date: 2021-12-21 10:29:00
- * @LastEditTime: 2021-12-21 10:55:22
- */
- #include <algorithm>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int dayOfYear(string date) {
- if (date.size() != 10) {
- return 0;
- }
- string year = date.substr(0, 4);
- string month = date.substr(5, 2);
- string day = date.substr(8, 2);
- int y = stoi(year);
- int m = stoi(month);
- int d = stoi(day);
- int a[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- if (y != 1990 && (y % 4 == 0)) a[2] += 1;
- int ret = 0;
- for (int i = 1; i < m; i++) {
- ret += a[i];
- }
- return d + ret;
- }
- int main() { cout << dayOfYear("2020-12-21"); }
|