We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There are ways to make code even shorter but this is far less readable than the above one, without any reduction in complexity since constants dont count. This is really short problem but 'readability' is really important factor in designing large softwares and shouldnt be ignored like this.
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Same number of lines, less variables, no string comparisons. One
atoi
though.int main() {
}
There are ways to make code even shorter but this is far less readable than the above one, without any reduction in complexity since constants dont count. This is really short problem but 'readability' is really important factor in designing large softwares and shouldnt be ignored like this.
Can't agree more about readability in real projects. I just wanted to add more challenge for myself for this particular problem.
unable to get your code...please if you could explain a bit how it is working.
CAN YOU PLEASE EXPLAIN THE BELOW CODE: char plus12 = n_hour >= 12; n_hour += time[8] == 'P' ? (plus12 ? 0 : 12) : (plus12 ? -12 : 0); printf("%02d:%.*s:%.*s", n_hour, 2, time + 3, 2, time + 6);