0

Military Time Code coach problem

Why is this not passing all the cases? #include <stdio.h> #include <string.h> int main() { char ntime[10]; int i=0, j, k, l; fgets(ntime,10,stdin); //printf("%s",ntime); l = strlen(ntime); for(j=0;j<l;j++){ if(ntime[l-j-1] == 'A'){ for(i=0;i<l-3;i++){ printf("%c",ntime[i]); } return 1; } } if(ntime[1] == ':'){ switch(ntime[0]){ case '1' : printf("13"); break; case '2' : printf("14"); break; case '3' : printf("15"); break; case '4' : printf("16"); break; case '5' : printf("17"); break; case '6' : printf("18"); break; case '7' : printf("19"); break; case '8' : printf("20"); break; case '9' : printf("21"); break; default : break; } for(i=1;i<l-3;i++){ printf("%c",ntime[i]); } return 1; }else if(ntime[2]==':'){ switch(ntime[1]){ case '0' : printf("22"); break; case '1': printf("23"); break; case '2': if(ntime[3]=='0' && ntime[4]=='0'){ printf("24"); }else{ printf("00"); } break; default : break; } for(i=2;i<l-3;i++){ printf("%c",ntime[i]); } return 2; } return 0; }

15th Aug 2020, 3:16 PM
Roderick Davis
Roderick Davis - avatar
1 Respuesta