Skip to content

Instantly share code, notes, and snippets.

@bojieli
Created March 20, 2015 15:45
Show Gist options
  • Save bojieli/188fee21986e488128aa to your computer and use it in GitHub Desktop.
Save bojieli/188fee21986e488128aa to your computer and use it in GitHub Desktop.
#include<stdio.h>
struct cal {
int hour, minute, second, day, month, year;
};
struct cal convert(struct cal in) {
struct cal out;
in.year -= 2000;
int past_years = in.month >= 3 ? in.year + 1 : in.year;
int days = in.year * 365 + (past_years + 3) / 4 - (past_years + 99) / 100 + (past_years + 399) / 400;
const int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i;
for (i=0; i < in.month - 1; i++)
days += month[i];
days += in.day - 1;
out.day = days % 100 + 1;
days /= 100;
out.month = days % 10 + 1;
days /= 10;
out.year = days;
unsigned int time = (long long)(in.hour * 3600 + in.minute * 60 + in.second) * 100000 / 86400;
out.second = time % 100;
time /= 100;
out.minute = time % 100;
time /= 100;
out.hour = time;
return out;
}
int main() {
int i, n;
scanf("%d", &n);
for (i=0; i<n; i++) {
struct cal c, out;
scanf("%d:%d:%d %d.%d.%d", &c.hour, &c.minute, &c.second, &c.day, &c.month, &c.year);
out = convert(c);
printf("%d:%d:%d %d.%d.%d\n", out.hour, out.minute, out.second, out.day, out.month, out.year);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment