Created
August 4, 2016 12:17
-
-
Save CraigRodrigues/685c5b3654ea5298265fa2bbcbd1d9ee to your computer and use it in GitHub Desktop.
HackerRank - Algorithms - Warmup - Time Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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