본문 바로가기

문제 풀이/문제 풀이(BOJ)

[Silver V] 연도 진행바 - 1340

[문제 위치]

https://www.acmicpc.net/problem/1340

[문제 풀이]

#include <iostream>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

int main() {
    map<string, int> month_map = {
        {"January", 1}, {"February", 2}, {"March", 3}, {"April", 4},
        {"May", 5}, {"June", 6}, {"July", 7}, {"August", 8},
        {"September", 9}, {"October", 10}, {"November", 11}, {"December", 12}
    };

    string month_str, day_str, year_time, time_str;
    getline(cin, month_str, ' ');
    getline(cin, day_str, ',');
    cin >> year_time >> time_str;

    int day = stoi(day_str);
    int year = stoi(year_time);
    int hour, minute;
    sscanf(time_str.c_str(), "%d:%d", &hour, &minute);
    int month = month_map[month_str];

    tm current_tm = {};
    current_tm.tm_year = year - 1900;
    current_tm.tm_mon = month - 1;
    current_tm.tm_mday = day;
    current_tm.tm_hour = hour;
    current_tm.tm_min = minute;
    current_tm.tm_sec = 0;

    tm start_tm = {};
    start_tm.tm_year = year - 1900;
    start_tm.tm_mon = 0;
    start_tm.tm_mday = 1;

    tm end_tm = {};
    end_tm.tm_year = year - 1900 + 1;
    end_tm.tm_mon = 0;
    end_tm.tm_mday = 1;

    time_t current_time = mktime(&current_tm);
    time_t start_time = mktime(&start_tm);
    time_t end_time = mktime(&end_tm);

    double elapsed = difftime(current_time, start_time);
    double total = difftime(end_time, start_time);

    cout << fixed << setprecision(15) << (elapsed / total) * 100 << '\n';

    return 0;
}

'문제 풀이 > 문제 풀이(BOJ)' 카테고리의 다른 글

[Silver V] 돌려 돌려 돌림판!  (3) 2025.08.08
[Silver V] 젓가락 - 24228  (0) 2025.08.06
[Silver V] 메시지 - 1384  (2) 2025.08.03
[Silver V] 욕심쟁이 돼지 - 3060  (1) 2025.08.03
[Silver V] 이름 궁함 - 15312  (0) 2025.08.02