Array ( [0] => [1] => questions [2] => Strings [3] => Timing-Format ) Strings | Timing Format | THE INQUISITIVE





Timing Format

LEVEL:Beginner

Description

Given a String. You have to convert the given time i,e, 12hours format to 24 hours format.

Input Format

First line contains a string.

Output Format

Print the resultant time in 24 hours format.


Example 1:

Input
2.30 PM	
Output
14.30
Example 2:

Input
11.00 AM			
Output
11.00
Example 3:

Input
8.00 PM
Output
20.00

oops

Login to see Discussion




Approach


Step-i) get the length of the given string
Step-ii) create a empty string new_time
Step-iii) if last second character of the string is P go to next step else go to vii
Step-iv) get the hour part from the string
Step-v) if hours equal to 12 append 00 to new_time and copy the rest of the string
Step-vi) else copy the entire string and return the time
Step-vii) get the hours part from the string
Step-viii) add 12 to the hours part and append to the new_time
Step-ix) add rest of the string as it is to the new_time
Step-x)return the string

Time Complexity : O(1)
Space Complexity: O(1)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution