Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- /*
- * function classifying an email.
- * return:
- * 1 for likely legitimate,
- * 0 for dubious,
- * -1 for likely spam.
- */
- int detect(vector<string>& bad, vector<string>& good, vector<string>& email) {
- int badWords = 0;
- int goodWords = 0;
- for (int x = 0; x<email.size(); x++) {
- for (int y = 0; y<bad.size(); y++) {
- if (email[x]==bad[y]) {
- badWords++;
- }
- }
- for (int y = 0; y<good.size(); y++) {
- if (email[x]==good[y]) {
- goodWords++;
- }
- }
- }
- if (badWords>goodWords) {
- return -1;
- }
- else if (badWords<goodWords) {
- return 1;
- }
- else {
- return 0;
- }
- }
- vector<string> bad;
- vector<string> good;
- vector<string> email;
- int main() {
- FILE *fr, *fw;
- int B, G, E, N;
- int spam = 0, legit = 0;
- cin >> B;
- bad.resize(B);
- for (int i=0; i<B; i++) cin >> bad[i];
- cin >> G;
- good.resize(G);
- for (int i=0; i<G; i++) cin >> good[i];
- cin >> E;
- for (int j=0; j<E; j++) {
- cin >> N;
- email.resize(N);
- for (int i=0; i<N; i++) cin >> email[i];
- int res = detect(bad, good, email);
- if (res == -1) spam++;
- if (res == 1) legit++;
- }
- cout << spam << " " << legit << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement