Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12 to 24 hr format #843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions SOLUTIONS/12-to-24-hr-format.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
static void convert(String str)
{

int h1 = (int)str.charAt(1) - '0';
int h2 = (int)str.charAt(0) - '0';
int hh = (h2 * 10 + h1 % 10);


if (str.charAt(8) == 'A')
{
if (hh == 12)
{
System.out.print("00");
for (int i = 2; i <= 7; i++)
System.out.print(str.charAt(i));
}
else
{
for (int i = 0; i <= 7; i++)
System.out.print(str.charAt(i));
}
}

else
{
if (hh == 12)
{
System.out.print("12");
for (int i = 2; i <= 7; i++)
System.out.print(str.charAt(i));
}
else
{
hh = hh + 12;
System.out.print(hh);
for (int i = 2; i <= 7; i++)
System.out.print(str.charAt(i));
}
}
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);

String str = sc.nextLine();
convert(str);


}
}