Skip to content

Instantly share code, notes, and snippets.

@igoreon
Created January 9, 2018 20:51
Show Gist options
  • Save igoreon/cbc8ecb20fbb309cad7bc478b6ebd0e6 to your computer and use it in GitHub Desktop.
Save igoreon/cbc8ecb20fbb309cad7bc478b6ebd0e6 to your computer and use it in GitHub Desktop.
from seconds to h:mm:ss
#include <iostream>
using namespace std;
int
main ()
{
int sec;
cin >> sec;
int hour = 3600;
int min = 60;
hour = sec / hour;
min = (sec - (hour * 3600)) / min;
sec = sec - ((hour * 3600) + (min * 60));
if (min >= 10 && sec >= 10)
{
cout << hour << ":" << min << ":" << sec;
} // ??????? ??????????
else if (hour >= 24 && min >= 10 && sec > 10)
{
cout << hour - 24 << ":" << min << ":" << sec;
}
else if (hour < 24 && min < 10 && sec < 10)
{
cout << hour << ":" << 0 << min << ":" << 0 << sec;
} // ?? if
else if (hour >= 24 && min < 10 && sec < 10)
{
cout << hour - 24 << ":" << 0 << min << ":" << 0 << sec;
}
else if (hour < 24 && min < 10 && sec >= 10)
{
cout << hour << ":" << 0 << min << ":" << sec;
}
else if (hour >= 24 && min < 10 && sec >= 10)
{
cout << hour - 24 << ":" << 0 << min << ":" << sec;
}
else if (hour < 24 && min >= 10 && sec <= 10)
{
cout << hour << ":" << min << ":" << 0 << sec;
}
else if (hour >= 24 && min >= 10 && sec <= 10)
{
hour -= 24;
cout << hour - 24 << ":" << min << ":" << 0 << sec;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment