Editorial for N giây


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
  • Với thời gian ~n~ giây trôi qua, ta có số giờ trôi qua là ~h=(n/3600)~ ~mod~ ~24~, số phút trôi qua nằm ngoài ~h~ giờ là ~m = (n~ ~mod~ ~3600)/60~ ~mod~ ~60~, số giây còn thừa là ~s = (n~ ~mod~ ~3600)~ ~mod~ ~60~.
  • Sử dụng công thức trên ta có thể dễ dàng tính được giờ phút giây hiện tại. Lưu ý format của output.
Code tham khảo
void print(int h) {
    if(h < 10) cout << 0 << h;
    else cout << h;
}

int main() {
    int n; cin >> n;    
    int h = (n / 3600) % 24;
    int m = ((n % 3600) / 60) % 60;
    int s = ((n % 3600) % 60);
    print(h);
    cout << ":";
    print(m);
    cout << ":";
    print(s);
}