Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Created August 4, 2016 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/685c5b3654ea5298265fa2bbcbd1d9ee to your computer and use it in GitHub Desktop.
Save CraigRodrigues/685c5b3654ea5298265fa2bbcbd1d9ee to your computer and use it in GitHub Desktop.
HackerRank - Algorithms - Warmup - Time Conversion
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(void)
{
int hours, minutes, seconds;
char time[3];
scanf("%d:%d:%d%s", &hours, &minutes, &seconds, time);
if (hours < 12 && (strcmp("PM",time) == 0))
{
hours += 12;
}
if (hours == 12 && (strcmp("AM",time) == 0))
{
hours = 0;
}
printf("%02d:%02d:%02d", hours, minutes, seconds);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment