summaryrefslogtreecommitdiffstats
path: root/2022-2/L01/mitsuo/aux.cpp
blob: bd9417d62d0ced022a5297bee6e2e86ec1e679cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Auxiliary/helper/reusable functions */

#include <iostream>
#include <iomanip>

#include "aux.h"

using namespace std;

/* "dd/mm/yyyy"  ->  yyyymmdd (int) */
int readdate(istream &is)
{
    char c;
    int d, m, y;

    is >> d >> c
       >> m >> c
       >> y;

    return y * 10000 + m * 100 + d;
}

/* yyyymmdd (int)  ->  "dd/mm/yyyy" */
void writedate(ostream &os, int intdate)
{
    int d, m, y;
    
    d = intdate % 100;
    intdate /= 100;
    m = intdate % 100;
    intdate /= 100;
    y = intdate;
    
    os << WR0(2, 2, y) << '/' 
       << WR0(2, 2, m) << '/' 
       << WR0(2, 2, d) << '\n';
}