行李牌上的編號最前面三個字是機場程式碼,比如 PEK-0815 裡的 PEK。寫 airport_code(ticket),返回這三個字。編號至少有 3 個字。
airport_code("PEK-0815")→'PEK'airport_code("LHR")→'LHR'string airport_code(const string &ticket)#include <string>
using namespace std;
string airport_code(const string &ticket) {
string code = "";
// 在這裡寫:用 substr 取最前面 3 個字
return code;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。