Einfach 0 gelöst 0% Erfolgsquote

Notification Costs

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

Das lernst du

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

Problem

Übersetzung anzeigen

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.

Einschränkungen

0 ≤ number of messages ≤ 10,000

Texts have 1 to 2,000 characters

Beispiele

Beispiel 1
Eingabe:
messages = ["email Welcome!", "sms Your code is 1234", "push New follower"]

Erwartete Ausgabe:
expected = 6
Eingabe:
std::vector<std::string> messages = {"email Welcome!", "sms Your code is 1234", "push New follower"};

Erwartete Ausgabe:
long long expected = 6;
Eingabe:
string[] messages = new string[] {"email Welcome!", "sms Your code is 1234", "push New follower"};

Erwartete Ausgabe:
long expected = 6;

Erläuterung

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

Beispiel 2
Eingabe:
messages = ["sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]

Erwartete Ausgabe:
expected = 10
Eingabe:
std::vector<std::string> messages = {"sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};

Erwartete Ausgabe:
long long expected = 10;
Eingabe:
string[] messages = new string[] {"sms aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};

Erwartete Ausgabe:
long expected = 10;

Erläuterung

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

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

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

Hinweis 2

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

Hinweis 3

Push messages cost nothing, so they add 0.

Erwartete Komplexität

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.