View Code of Problem 3310

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n;
    int y, m, d, h, mm, s;
    string str;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d/%d/%d-%d:%d:%d", &y, &m, &d, &h, &mm, &s);
        if (h == 0)
        {
            h = 12;
            str = "am";
        }
        else if (h < 12)
        {
            str = "am";
        }
        else
        {
            if (h > 12)
                h -= 12;
            str = "pm";
        }
        printf("%02d/%02d/%04d-%02d:%02d:%02d%s\n", m, d, y, h, mm, s, str.c_str());
    }
}

Double click to view unformatted code.


Back to problem 3310