Editorial for Phân loại Email Quan Trọng
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Xem các lời giải dưới đây là con đường chỉ dẫn để giải được bài tập, nếu phát hiện gian lận sẽ bị chặn thamg gia các bài tập sáng tạo bởi chúng tôi và bị báo cáo với Admin LQDOJ. Mong mọi người sớm giải được problem.
C++
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool contains_keyword(const string& text, const vector<string>& keywords) {
for (const string& keyword : keywords) {
if (text.find(keyword) != string::npos) {
return true;
}
}
return false;
}
string classify_email(const string& subject, const string& body) {
vector<string> important_keywords = {"họp", "deadline", "thanh toán", "khẩn cấp"};
vector<string> normal_keywords = {"báo cáo", "thông báo", "dự án"};
if (contains_keyword(subject, important_keywords) || contains_keyword(body, important_keywords)) {
return "Quan trọng";
} else if (contains_keyword(subject, normal_keywords) || contains_keyword(body, normal_keywords)) {
return "Bình thường";
} else {
return "Không quan trọng";
}
}
int main() {
int n;
cin >> n;
cin.ignore(); // Loại bỏ ký tự xuống dòng sau khi nhập số
for (int i = 0; i < n; i++) {
string subject, body;
getline(cin, subject);
getline(cin, body);
cout << classify_email(subject, body) << endl;
}
return 0;
}
Pascal
program EmailClassification;
uses SysUtils;
function contains_keyword(text: string; keywords: array of string): boolean;
var
i: integer;
begin
for i := 0 to High(keywords) do
if Pos(keywords[i], text) > 0 then
begin
contains_keyword := true;
Exit;
end;
contains_keyword := false;
end;
function classify_email(subject, body: string): string;
const
important_keywords: array[0..3] of string = ('họp', 'deadline', 'thanh toán', 'khẩn cấp');
normal_keywords: array[0..2] of string = ('báo cáo', 'thông báo', 'dự án');
begin
if contains_keyword(subject, important_keywords) or contains_keyword(body, important_keywords) then
classify_email := 'Quan trọng'
else if contains_keyword(subject, normal_keywords) or contains_keyword(body, normal_keywords) then
classify_email := 'Bình thường'
else
classify_email := 'Không quan trọng';
end;
var
n, i: integer;
subject, body: string;
begin
ReadLn(n);
for i := 1 to n do
begin
ReadLn(subject);
ReadLn(body);
WriteLn(classify_email(subject, body));
end;
end.
Python
def contains_keyword(text, keywords):
for keyword in keywords:
if keyword in text:
return True
return False
def classify_email(subject, body):
important_keywords = ["họp", "deadline", "thanh toán", "khẩn cấp"]
normal_keywords = ["báo cáo", "thông báo", "dự án"]
if contains_keyword(subject, important_keywords) or contains_keyword(body, important_keywords):
return "Quan trọng"
elif contains_keyword(subject, normal_keywords) or contains_keyword(body, normal_keywords):
return "Bình thường"
else:
return "Không quan trọng"
n = int(input())
for _ in range(n):
subject = input()
body = input()
print(classify_email(subject, body))
Comments