[백준 5666] Hot Dogs (C#, C++) - soo:bak
작성일 :
문제 링크
설명
핫도그 먹기 대회에서 참가자 수와 소비된 핫도그 개수가 주어졌을 때,
참가자 한 명당 평균적으로 몇 개의 핫도그를 먹었는지를 소수점 둘째 자리까지 출력하는 문제입니다.
접근법
- 한 줄에
핫도그 개수
와참가자 수
가 주어지며, 테스트케이스가 여러 줄일 수 있습니다. - 각 줄마다, 핫도그 개수 ÷ 참가자 수를 계산하여 평균을 구합니다.
- 해당 값을 소수점 아래 둘째 자리까지 출력해야 함에 주의합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
class Program {
static void Main() {
string? line;
while ((line = Console.ReadLine()) != null) {
var parts = line.Split();
int h = int.Parse(parts[0]);
int p = int.Parse(parts[1]);
Console.WriteLine((h / (double)p).ToString("F2"));
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(2);
int h, p;
while (cin >> h >> p)
cout << (double)h / p << "\n";
return 0;
}