항상 일정한 속도로 달리는 기계가 있다고 합시다. 이 기계의 100m 달리기 기록(초)을 입력받으면 마라톤에서의 기록(시:분:초)을 구하시면 됩니다. 마라톤 경기에서 달리는 거리는 42.195km입니다. 100m 달리기와 마라톤의 코스는 모두 직선이라고 합니다(회전 시 걸리는 시간을 고려하지 않습니다). 기계의 파손 및 배터리 방전 시간도 고려하지 않습니다.
39개의 풀이가 있습니다.
record = float(input('enter your record: '))
time = record * 42195 / 100
marathon_record = []
marathon_record.append(int(time) // 3600)
marathon_record.append((int(time) - marathon_record[0] * 3600) // 60)
marathon_record.append((int(time) - marathon_record[0] * 3600 - marathon_record[1] * 60))
marathon_record.append(int(round(time - int(time), 2) * 100))
print('The marathon record is: {}h {}m {}s {:0<}'.format(marathon_record[0], marathon_record[1], marathon_record[2], marathon_record[3]))
시간을 초로 받으면 몇시간 몇분 몇초인지 기록을 알려주고 소수점 둘째 자리까지 알려줍니다... 다 쓰고 나니까 %연산자가 생각나네요,,,
namespace KangMinSeung
{
static class Program
{
static void Main(string[] args)
{
//공용변수 [나머지, 시간 , 분 , 초 , 밀리초]
double Remainder, Hour, Min, Second, MiliSecond;
//입력 받기
Console.Write("100M 걸리는 시간을 입력해주세요 : ");
string Time = Console.ReadLine();
Console.Write("거리를 m단위로 입력해주세요. : ");
string Distance = Console.ReadLine();
//입력 받은 값 초단위로 변환
double Total = int.Parse(Distance) / 100.0 * int.Parse(Time);
//시간 구하기
Hour = Total / 3600; //걸리는 시간 추출
Remainder = Hour - (int)Hour; //소수점 시간 추출
Min = Remainder * 60; //소수점 시간 -> 분으로 변환
Remainder = Min - (int)Min; //소수점 분 추출
Second = Remainder * 60; //소수점 분 -> 초로 변환
MiliSecond = (Second - (int)Second) * 1000; //소수점 초 -> 밀리세컨드 변환
Console.WriteLine($"{Distance}m 기준 소요시간은 {(int)Hour}시간 {(int)Min}분 {(int)Second}초 {Math.Floor(MiliSecond)} 입니다.");
}
}
}
걸리는 시간 : 42195m 기준 소요시간은 1시간 10분 19초 500 입니다.
파이썬입니다.
def main():
r = float(input("100미터를 몇 초에 뛸 수 있나요?: "))
d = 421.95
t = r * d
h, m, s = 0, 0, 0.0
h, t = divmod(t, 3600)
m, s = divmod(t, 60)
print(f"마라톤 기록: {h:.0f}시간 {m:.0f}분 {s:.2f}초")
if __name__ == '__main__':
main()
def Maraton(a):
k = 42195*(a/100)
if k > 60:
min = k//60
sec = k%60
else:
min = 0
sec = k
print('총 %d분 %f초가 걸립니다.'% (min,sec))
a = int(input('100미터 달리기에 몇초가 걸리는지 입력:'))
Maraton(a)
Python 3
import datetime
record: float = 42.195 * 10 ** 3 / (100 / float(input('100m 기록(sec): ')))
print(f"마라톤 기록(h:m:s): {str(datetime.timedelta(seconds=record))}")
#include <stdio.h>
int main()
{
int h,m,s;
printf("100m 달리기의 기록(초):");
scanf("%d",&h);
s=42195/100*h;
printf("%d\n",s);
h=s/3600;
m=(s%3600)/60;
s=s%60;
printf("%d:%d:%d",h,m,s);
getch();
return 0;
}
파이썬 3.8.5입니다
def marathon_record(sec): import numpy as np
초 기준
record = 42.195e3 / 100 * sec분 기준
record = record / 60 return np.round(record, 3)print(marathon_record(12))
import java.util.Scanner;
public class MyClass{
public static void main(String []args) {
Scanner s = new Scanner(System.in);
double t = s.nextFloat();
double mt = 421.95*t;
System.out.printf("마라톤 기록 : %d시간 %d분 %d초", (int)(mt/3600), (int)((mt%3600)/60),(int)(mt%60));
}
}
x=float(input('기록'))
time=42195/100
hour=(x*time)//(60*60)
minute=((x*time)%(60*60))//60
second=((x*time)%(60*60))%60
print('{}시간 {}분 {}초'.format(int(hour), int(minute), second))
def record_marathon(sec):
"""100m 기록으로 마라톤 42.195km 기록을 구합니다.
sec: 100m 기록, 단위 초"""
return 42.195 * sec / 0.1
# example
record_marathon(12)
m = 42195
bak = int(input())
record = (m/100)*bak
if record//60 >= 60:
print(record//3600,"시간",record//60-60,"분",record%60,"초")
else: print(record//60,"분",record%60,"초")
python 3.9.5입니다. 세 줄로 작성해 보았으며, 시간, 분, 초 단위로 나타냅니다.
short_record = int(input('100m 기록을 초 단위로 숫자만 입력하세요. '))
time = short_record * 421.95
print(f'{int(time//3600)}시간 {int((time%3600)//60)}분 {int(((time%3600)%60))}초')
실행 결과입니다.
100m 기록을 초 단위로 숫자만 입력하세요. 20
2시간 20분 39초
#codingdojing_marathon
s = eval(input("100m record(s): "))
m_s = 100 / s
marathon_record_s = 42195/m_s # second
re1 = round(marathon_record_s // 3600)
re2 = round((marathon_record_s % 3600) // 60)
re3 = round((marathon_record_s % 3600) % 60)
print(f'marathon expected record: {re1}:{re2}:{re3}' )
일 시 분 초 단위입니다.
S = float(input("초 : ")) * 421.95
while 1:
D = int(S // 86400)
S -= D * 86400
H = int(S // 3600)
S -= H * 3600
M = int(S // 60)
S -= M * 60
break
print("완주까지 {}일 {}시 {}분 {}초 걸립니다.".format(D, H, M, S))
t = int(input("로봇의 100m 기록을 입력하시오(s):"))
def record(time):
a = 42.195 * 1000 #Km를 m로 환산합니다.
c = 100/t # 로봇의 속력을 구합니다.(m/s)
b = a/c # 시간 = 거리 / 속력
print("42.195km 예상기록은 {}초({}분) 입니다.".format(b,b/60)) # 마라톤 기록을 print
record(t)
def compute_record(record):
time = record * 42195 / 100
ss = time% 60
temp = time // 60
mm = int(temp % 60)
hh = int(temp // 60)
print('{0}시간 {1}분 {2}초'.format(hh,mm,ss))
if __name__ == '__main__':
record = int(input()) # 초로 입력을 받는다
compute_record(record)
sec= float(input('100m 기록(초) : ')) / 100 * 42195
hour=0;min=0;second=0
if sec // 3600 >= 1:
hour= sec // 3600
sec -= hour*3600
if sec//60>=1:
min= sec//60
sec-= min*60
second=sec
print('%d시간 %d분 %0.2f초'%(hour,min,second))
a=(float(input('기록을 입력하시오(초)')) 속력=100/a 마라톤 기록_초=속력*42195 마라톤 기록_시간=마라톤 기록_초/3600 print('기계의 마라톤 기록은 %d시간 입니다'마라톤 기록_시간)
double ma = 42.195;
Scanner s = new Scanner(System.in);
System.out.println("100m 달리기 기록을 입력하세요.");
int n = s.nextInt();
double time = ma*10*n;
System.out.printf("%d : %d : %d", (int)time/3600, (int)time%3600/60, (int)time%3600%60);
코린이입니다. 꾸벅
a = float(input("기계의 100m 달리기 기록을 입력하세요."))
tt = a*421.95 #마라톤 전체 기록(초)
h = tt//3600 #마라톤 시간
m = (tt//60)%60 #마라톤 분
s = tt%60 #마라톤 초
print("기계의 마라톤 달리기 기록은 %d시간 " % h + "%d분 " % m + "%.2f초 입니다" % s)
a= int(input("100m 달리기 몇초:"))
v = 100/a
time = 42195/v
print("마라톤 기록은",time//3600,"시간",time%3600//60,"분",time%3600%60,"초")
import datetime
l = 42.195 * 1000 #미터로 환산
sec = int(input("100m 초를 입력하세요 : "))
m = 100/sec #초당 움직인 거리
record = l/m # 42.195km 달리는데 걸린 시간(초)
print(f"{(datetime.timedelta(seconds=record))}") #시:분:초 로 표시
a = input('이 기계는 100m를 몇초에 지나가나요?')
b = 42.195*10*float(a)
h = b//3600
m = (b%3600)//60
s = b%60
print(f'이 이계는 42.195km를 {b}초에 지나갑니다.')
print(f'이 이계는 42.195km를 {h}시간, {m}분, {s}초에 지나갑니다.')
package org.javaturotials.ex;
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double hun = sc.nextDouble();
double mil = hun*10; //1km 뛰는데 걸리는 시간
double mara = mil *42.195;
int hour= (int)mara/3600;
int min = (int)(mara - (3600*hour))/60;
int sec = (int)(mara - 3600*hour-min*60);
System.out.println(hour + "시간 " + min + "분 " + sec + "초");
}
}
#include <stdio.h>
#define MARATON 42195
int main(int argc, char *argv[])
{
double record;
double sec_result;
printf("100m 달리기 기록 입력(sec):");
scanf("%lf", &record);
result = record * MARATON / 100;
printf("마라톤에서 기록 환산: %lf초\n", result);
return 0;
}
package com.algorithm.algorithmpractice.dojang;
public class Marathon {
private static double takeTime(int input){
final int length = 42195;
double times = length / 100.0;
return input * times;
}
public static void main(String[] args) {
System.out.println(takeTime(5));
}
}
dst=42195
unit_dst=100
unit_rec=float(input('100미터기록 (초)?'))
rec_sec=dst/unit_dst*unit_rec
h=rec_sec//3600
rec_sec=rec_sec%3600
m=rec_sec//60
rec_sec=rec_sec%60
s=rec_sec
print ('%02d:%02d:%02d' %(h,m,s))
Python. 과제 자체보다는 '시/분/초'로 표기하는 것이 더 어려웠네요.
sec=int(input('100m 달리기 기록(초)을 입력하시오. : '))
sec_2=sec/100 #100미터 기록을 1미터당 기록으로 변경
S=sec_2*42195 #마라톤 코스 길이 곱하기
D, H, M = 0, 0, 0 #여기서부터는 최종 마라톤 기록인 '초'를 '일/시/분/초'로 나타내기 위한 것
while S > 86400: #60*60*24 / 하루를 초로 나눈 것
S -= 86400
D += 1
while S > 3600: #60*60
S -=3600
H += 1
while S > 60:
S -= 60
M += 1
print('해당 기계의 마라톤 예상 완주 기록은 {0}일 {1}시간 {2}분 {3:0.2f}초입니다.'.format(D, H, M, S)) #소수점 이하 2자리까지만 표시
dart
import 'dart:math';
marathonRecord(num sec100m) {
int rec = (sec100m * 42195 / 100).truncate(); // 소수점 이하 버림
print("${sec100m}sec/100m => ${rec ~/ 3600}:${rec ~/ 60}:${rec % 60}");
}
void main() {
marathonRecord(2.1);
marathonRecord(7.25);
marathonRecord(11);
marathonRecord(186);
}
2.1sec/100m => 0:14:46
7.25sec/100m => 0:50:59
11sec/100m => 1:77:21
186sec/100m => 21:1308:2
max_len = 42.195 * 1000 / 100 #마라톤 거리 * M변환 / 기준거리(100m)
input_val = input("100M 기록 입력 : ")
total = max_len * float(input_val) #초 기록
min = total // 60
sec = total % 60
hour = int(min // 60)
min = int(min % 60)
print("{}시간 {}분 {}초".format(hour, min, sec))
num = int(input("Enter 100m/s:"))
hour = int(num/3600)
minute = int((num%3600)/60)
second = int((num%3600)%60)
print(hour,"H",minute,"M",second,"S")
rec = int(input('100m 달리기 기록(초)을 입력하세요: '))
list = [42195 * rec / 100]
for i in range(2):
list.append(int(list[i]//60))
list[i] %= 60
print('42.195km 마라톤에서의 소요시간: {}시 {}분 {:.2f}초'.format(list[2], list[1],list[0]))
def marathon_cal(your_record):
distance = 42195
record = float(your_record)
h = 0
m = 0
s = 0
seconds = record / 100 * distance
h = (seconds // 60) // 60
m = (seconds // 60) % 60
s = seconds % 60
print ("당신은 42.195Km를 달리면 {}시간 {}분 {}초가 걸립니다".format(h,m,s))
your_record = input ("100m를 몇초에 뛸수 있나요?: ")
marathon_cal (your_record)