fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. int hour, m, s;
  6. char period[3]; // "AM" or "PM"
  7.  
  8. scanf("%d:%d:%d%2s", &hour, &m, &s, period);
  9.  
  10. // Chuyển đổi sang định dạng 24h
  11. if (strcmp(period, "AM") == 0) {
  12. if (hour == 12) hour = 0; // 12AM -> 00
  13. } else {
  14. if (hour != 12) hour += 12; // 1PM–11PM -> cộng thêm 12
  15. }
  16.  
  17. // In ra định dạng hh:mm:ss với đủ 2 chữ số
  18. printf("%02d:%02d:%02d\n", hour, m, s);
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5336KB
stdin
Standard input is empty
stdout
2085237052:21970:-271178560