
Электронные часы - 2 2948 на informatics Электронные часы показывают время в формате h:mm:ss, то
есть сначала записывается количество часов, потом обязательно двузначное количество минут, затем обязательно двузначное количество секунд. Количество минут и секунд при необходимости дополняются до двузначного числа нулями. С начала суток прошло n секунд. Выведите, что покажут часы. Входные данные Вводится целое число n. Выходные данные Выведите ответ на задачу, соблюдая требуемый формат. For example:

Ответы на вопрос

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#pragma GCC optimize("Ofast")
#define ll long long
using namespace std;
ll digits(ll a){
if(a == 0)
return 1;
ll cnt = 0;
while(a > 0){
a /= 10;
cnt++;
}
return cnt;
}
int main() {
ll n;
cin >> n;
ll h = n/3600;
h %= 24;
n %= 3600;
ll m = n/60;
ll s = n % 60;
cout << h << ':';
if(digits(m) == 1)
cout << 0;
cout << m << ':';
if(digits(s) == 1)
cout << 0;
cout << s;
}
на информатиксе 100 :)



To solve this problem, you can use simple mathematical operations to convert the given number of seconds into the desired format of hours, minutes, and seconds.
Here's the algorithm to solve this problem:
- Read the input value of seconds, let's say it's stored in the variable
n
. - Calculate the number of hours by dividing
n
by 3600 (the number of seconds in an hour). Store this value in the variablehours
. - Calculate the remaining seconds after extracting the hours by taking the modulus of
n
with 3600. Store this value in the variableremaining_seconds
. - Calculate the number of minutes by dividing
remaining_seconds
by 60 (the number of seconds in a minute). Store this value in the variableminutes
. - Calculate the remaining seconds after extracting the minutes by taking the modulus of
remaining_seconds
with 60. Store this value in the variableseconds
. - Format the values of
hours
,minutes
, andseconds
to have two digits by adding leading zeros if necessary. - Print the formatted values in the required format:
hours:mm:ss
.
Here's an example implementation in Python:
pythonn = int(input()) # Read the input value of seconds
hours = n // 3600
remaining_seconds = n % 3600
minutes = remaining_seconds // 60
seconds = remaining_seconds % 60
# Format the values with leading zeros if necessary
formatted_hours = str(hours).zfill(2)
formatted_minutes = str(minutes).zfill(2)
formatted_seconds = str(seconds).zfill(2)
# Print the result in the required format
print(formatted_hours + ":" + formatted_minutes + ":" + formatted_seconds)
For example, if the input value of n
is 2948, the output will be:
makefile0:49:08
This means that the electronic clock will show 0 hours, 49 minutes, and 8 seconds.


Похожие вопросы
Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili