쉬움 0명 해결 정답률 0%

Notification Costs

Send messages through email, SMS and push channels that each compute their own cost.

배우게 될 내용

  • Give each channel its own cost rule
  • Round up to whole blocks of characters
  • Split a message into channel and text

문제

번역본 보기

Polymorphism lets code call the same method on different objects and get behaviour specific to each one. Here every channel computes the cost of a message its own way.

Each message is <channel> <text>, where the text is everything after the first space:

  • email: costs 1.
  • sms: costs 5 for every started block of 160 characters of text (1 to 160 characters is one block).
  • push: free.

Implement notification_cost(messages).

Input

messages: The messages to send. SMS texts have at least one character.

Output

Return the total cost.

제약 조건

0 ≤ number of messages ≤ 10,000

Texts have 1 to 2,000 characters

예시

예시 1
입력:
messages = ["email Welcome!", "sms Your code is 1234", "push New follower"]

예상 출력:
expected = 6
입력:
std::vector<std::string> messages = {"email Welcome!", "sms Your code is 1234", "push New follower"};

예상 출력:
long long expected = 6;
입력:
string[] messages = new string[] {"email Welcome!", "sms Your code is 1234", "push New follower"};

예상 출력:
long expected = 6;

설명

Email costs 1, the short SMS uses one block (5) and push is free: 6.

예시 2
입력:
messages = ["sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]

예상 출력:
expected = 10
입력:
std::vector<std::string> messages = {"sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};

예상 출력:
long long expected = 10;
입력:
string[] messages = new string[] {"sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};

예상 출력:
long expected = 10;

설명

161 characters need two 160-character blocks: 2 × 5 = 10.

접근 방법

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

힌트 1

Split each message once at the first space into channel and text.

힌트 2

For SMS, count blocks with ceiling division: (length + 159) / 160.

힌트 3

Push messages cost nothing, so they add 0.

예상 복잡도

O(total length) time, O(1) extra space

참고 자료

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

다른 사람의 풀이 보기

커뮤니티 솔루션

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