모든 챌린지
보통 0명 해결 정답률 0%

Weekly Payroll

Total a week's pay for salaried, hourly and commission employees, each paid by its own rule.

배우게 될 내용

  • Compute pay with a rule per employee type
  • Pay overtime above 40 hours
  • Sum decimal amounts accurately

문제

번역본 보기

A payroll system treats every employee as an Employee with a WeeklyPay() method, and each kind of employee overrides it.

Each employee is written as:

  • salaried <annual>: earns annual / 52.
  • hourly <rate> <hours>: earns rate × hours for the first 40 hours and 1.5 × rate for every hour beyond 40.
  • commission <base> <rate> <sales>: earns base + rate × sales.

Implement weekly_payroll(employees).

Input

employees: The employees. Numbers may have decimals.

Output

Return the total weekly pay. Answers within 1e-6 are accepted.

제약 조건

0 ≤ number of employees ≤ 10,000

All numbers are between 0 and 10^7; hours ≤ 100

예시

예시 1
입력:
employees = ["salaried 52000", "hourly 20 45"]

예상 출력:
expected = 1950.0
입력:
std::vector<std::string> employees = {"salaried 52000", "hourly 20 45"};

예상 출력:
double expected = 1950.0;
입력:
string[] employees = new string[] {"salaried 52000", "hourly 20 45"};

예상 출력:
double expected = 1950.0;

설명

The salaried employee earns 52000 / 52 = 1000. The hourly one earns 20 × 40 + 30 × 5 = 950. Total 1950.

예시 2
입력:
employees = ["commission 300 0.1 2500"]

예상 출력:
expected = 550.0
입력:
std::vector<std::string> employees = {"commission 300 0.1 2500"};

예상 출력:
double expected = 550.0;
입력:
string[] employees = new string[] {"commission 300 0.1 2500"};

예상 출력:
double expected = 550.0;

설명

300 + 0.1 × 2500 = 550.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Handle each employee type with its own formula.

힌트 2

Hourly pay is normal for the first 40 hours and 1.5 times the rate after that.

힌트 3

Keep decimals: salaries divided by 52 rarely give whole numbers.

예상 복잡도

O(number of employees) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.