#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
char* time = (char *)malloc(10240 * sizeof(char));
scanf("%s",time);
int count = 0;
int hh = (time[0] - '0') * 10 + (time[1] - '0');
for(int i=0;i < 10240;i++) {
if ((time[i] == 'P' || time[i] == 'p') && (time[i+1] == 'M' || time[i+1] =='m')) {
if (hh > 11) break;
if (hh == 24 )
hh = 0;
else
hh+=12;
break;
}
if ((time[i] == 'A' || time[i+1] =='a') && (time[i+1] == 'M' || time[i+1] =='m')) {
if (hh > 11) hh = 0;
break;
}
if (time[i] == '\0') {
break;
}
count++;
}
time[0] = hh/10 + '0';
time[1] = hh%10 + '0';
char* newTime = (char*) malloc(count* sizeof (char));
strncpy(newTime, time, count);
printf("%s", newTime);
return 0;
}
No comments:
Post a Comment