TopCoder

User's AC Ratio

100.0% (2/2)

Submission's AC Ratio

25.0% (3/12)

Tags

Description

有一家公司想要開發一個通知系統,用來通知顧客他們的最新資訊。他們通知顧客的管道有兩種:透過 Line 或透過 Email。

接下來,我們會給你一個叫做 Notificationabstract class,你需要使用「繼承」(Inheritance) 的方式來實作兩個通知系統:LineNotificationEmailNotification
當然,因為我們還沒學過怎麼接 API,所以我們現在會直接用 cout 來取代真正寄通知給顧客。

Notification 這個 abstract class 如下:

class Notification {
protected:
    string recipient;
    string message;

public:
    Notification(const string& recipient, const string& message);
    virtual void send() = 0;  // abstract method (pure virtual)
    virtual ~Notification();
};

你要實作的 class 有以下兩個:

  1. LineNotification

    • 繼承 Notification abstract class
    • 一個 private string 變數:lineId (line 的 l 是小寫 l,Id 的 I 是大寫 I)
    • 一個 public 函式:void setLineId(const string &lineId):將 private 的 lineId 變數設為參數給定的 lineId
    • override Notificationvoid send() 函式:輸出以下字串:"[Line] Sending message to <recipient> (<lineId>): <message>",其中 <recipient>, <lineId>, <message> 要分別用 LineNotification 裡面的變數取代
  2. EmailNotification

    • 繼承 Notification abstract class
    • 一個 private string 變數:email
    • 一個 public 函式:void setEmail(const string &email):將 private 的 email 變數設為參數給定的 email
    • override Notificationvoid send() 函式:輸出以下字串:"[Email] Sending message to <recipient> (<email>): <message>",其中 <recipient>, <email>, <message> 要分別用 EmailNotification 裡面的變數取代

請複製以下程式碼,並且將這兩個 class 定義在指定的區塊。請注意,請勿修改任何已經寫好的程式碼,你只能額外定義這兩個 class。

#include <iostream>
#include <vector>
#include <string>
#include "lib1048.h"

/*
    TODO: WRITE YOUR CODE HERE
*/

// IMPORTANT: DO NOTE MODIFY ANY CODE BELOW!
void sendNotification(Notification& notification) {
    notification.send();
}

int main() {
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string type, recipient, message;
        cin >> type >> recipient;
        cin.ignore(); // discard whitespace
        getline(cin, message);

        if (type == "Email") {
            string email;
            cin >> email;
            EmailNotification emailNotification = EmailNotification(recipient, message);
            emailNotification.setEmail(email);
            sendNotification(emailNotification);
        } else if (type == "Line") {
            string lineId;
            cin >> lineId;
            LineNotification lineNotification = LineNotification(recipient, message);
            lineNotification.setLineId(lineId);
            sendNotification(lineNotification);
        }
    }
}

Input Format

Note: 你不需要處理任何輸入,只需要按照題目說明實作兩個 class

輸入格式:
第一行有一個正整數 $n$,代表有幾筆測資。
接下來 $n$ 筆測資,每筆測資有三行。
第一行有兩個用空白隔開的字串,分別代表 type, recipient
第二行代表 message
第三行代表有一個字串代表 lineId 或 email (根據 type 決定)

Output Format

如果 type 是 Line,輸出 [Line] Sending message to <recipient> (<lineId>): <message>
如果 type 是 Email,輸出 [Email] Sending message to <recipient> (<email>): <message>

Sample Input 1

3
Line lemon
make lemonade
1emon
Email banana
banana green
banana@green.com
Email sprout
OOP is so fun
sprout@csie.ntu.edu.tw

Sample Output 1

[LINE] Sending message to lemon (1emon): make lemonade
[EMAIL] Sending message to banana (banana@green.com): banana green
[EMAIL] Sending message to sprout (sprout@csie.ntu.edu.tw): OOP is so fun

Hints

Problem Source

Subtasks

No. Testdata Range Score
1 0~4 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 1
2 1000 65536 65536 1
3 1000 65536 65536 1
4 1000 65536 65536 1