Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <math.

h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){

int hh, mm, ss ;


char t12[2];
scanf("%d:%d:%d%s", &hh, &mm, &ss, t12) ;
if (strcmp(t12,"PM")==0 && hh!=12) hh += 12 ;
if (strcmp(t12,"AM")==0 && hh==12) hh = 0 ;
printf("%02d:%02d:%02d", hh, mm, ss) ;
return 0;
}

JAVA
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT.
Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
String[] time = sc.nextLine().split(":");

String hours = time[0];


String minutes = time[1];
String seconds = time[2].substring(0,2);
String dayEve = time[2].substring(2,4);
if(dayEve.equals("AM")){
System.out.println((hours.equals("12")?"00":hours)
+":"+minutes+":"+seconds);
}else{
System.out.println((hours.equals("12")?hours:(Integer.parseInt(hours)
+12))+":"+minutes+":"+seconds);
}
}
}

You might also like