Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8.  * function classifying an email.
  9.  * return:
  10.  *   1 for likely legitimate,
  11.  *   0 for dubious,
  12.  *  -1 for likely spam.
  13.  */
  14. int detect(vector<string>& bad, vector<string>& good, vector<string>& email) {
  15.     int badWords = 0;
  16.     int goodWords = 0;
  17.  
  18.     for (int x = 0; x<email.size(); x++) {
  19.         for (int y = 0; y<bad.size(); y++) {
  20.             if (email[x]==bad[y]) {
  21.                 badWords++;
  22.             }
  23.         }
  24.         for (int y = 0; y<good.size(); y++) {
  25.             if (email[x]==good[y]) {
  26.                 goodWords++;
  27.             }
  28.         }
  29.     }
  30.  
  31.     if (badWords>goodWords) {
  32.         return -1;
  33.     }
  34.     else if (badWords<goodWords) {
  35.         return 1;
  36.     }
  37.     else {
  38.         return 0;
  39.     }
  40. }
  41.  
  42.  
  43. vector<string> bad;
  44. vector<string> good;
  45. vector<string> email;
  46.  
  47. int main() {
  48.     FILE *fr, *fw;
  49.     int B, G, E, N;
  50.     int spam = 0, legit = 0;
  51.  
  52.     cin >> B;
  53.     bad.resize(B);
  54.     for (int i=0; i<B; i++) cin >> bad[i];
  55.     cin >> G;
  56.     good.resize(G);
  57.     for (int i=0; i<G; i++) cin >> good[i];
  58.     cin >> E;
  59.     for (int j=0; j<E; j++) {
  60.         cin >> N;
  61.         email.resize(N);
  62.         for (int i=0; i<N; i++) cin >> email[i];
  63.         int res = detect(bad, good, email);
  64.         if (res == -1) spam++;
  65.         if (res == 1)  legit++;
  66.     }
  67.     cout << spam << " " << legit << endl;
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement