Skip to main content
Updated code, content
Source Link
Abel Tom
  • 1.2k
  • 1
  • 7
  • 9

C 136C (clang), 94 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}
h,m;f(){char a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);printf("%02d%02d",a=='a'?(h%12):(12+h%12),m);}

Normal readable format:Try it online!

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}

I'm here to learn, so any tips on how i can optimize the code are welcome.

@ Johan du Toit Thanks, for saving a few bytes!

C 136 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}

Normal readable format:

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}

I'm here to learn, so any tips on how i can optimize the code are welcome.

C (clang), 94 bytes

h,m;f(){char a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);printf("%02d%02d",a=='a'?(h%12):(12+h%12),m);}

Try it online!

I'm here to learn, so any tips on how i can optimize the code are welcome.

@ Johan du Toit Thanks, for saving a few bytes!

edited content
Source Link
Abel Tom
  • 1.2k
  • 1
  • 7
  • 9

C 136 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}

Normal readable format:

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}

I'm here to learn, so any tips on how i can optimize the code are welcome.

C 136 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}

Normal readable format:

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}

C 136 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}

Normal readable format:

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}

I'm here to learn, so any tips on how i can optimize the code are welcome.

Source Link
Abel Tom
  • 1.2k
  • 1
  • 7
  • 9

C 136 bytes

Input format 12:00am

f(){h,m a,b;scanf("%d:%d%c%c",&h,&m,&a,&b);if(a=='a'&&b=='m') printf("%02d%02d",h%12,m);if(a=='p'&&b=='m')printf("%02d%02d",12+h%12,m);}

Normal readable format:

void f()
{
 int h,m;
 char a,b;  
 scanf("%d:%d%c%c",&h,&m,&a,&b);    
 if(a=='a'&&b=='m')
   printf("%02d%02d\n",h%12,m); 
 if(a=='p'&&b=='m')
  printf("%02d%02d\n",12+h%12,m);
}