Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <algorithm>
- #include <string>
- using namespace std;
- int ricercaBinariaNonRicorsiva(string lista[], int n, string x)
- {
- int p, u, m;
- p = 0;
- u = n - 1;
- while(p <= u) {
- m = (p + u) / 2;
- if(lista[m] == x)
- return m; // valore x trovato alla posizione m
- if(lista[m] < x)
- p = m + 1;
- else
- u = m - 1;
- }
- // se il programma arriva a questo punto vuol dire che
- // il valore x non รจ presente in lista, ma se ci fosse
- // dovrebbe trovarsi alla posizione p (nota che qui p > u)
- return -1;
- }
- int main()
- {
- freopen("input.txt", "r", stdin); // redirects standard input
- freopen("output.txt", "w", stdout);
- int countPro, countCon;
- cin >> countCon;
- string arrCon[countCon];
- for(int i = 0; i < countCon; i++)
- cin >> arrCon[i];
- sort(arrCon, arrCon + countCon);
- cin >> countPro;
- string arrPro[countPro];
- for(int i = 0; i < countPro; i++)
- cin >> arrPro[i];
- sort(arrPro, arrPro + countPro);
- int f;
- cin >> f;
- int goodWords = 0, badWords = 0;
- for(int i = 0; i < f; i++)
- {
- int g;
- cin >> g;
- bool bad = false, good = false;
- string word;
- for(int j = 0; j < g; j++)
- {
- // usa j
- cin >> word;
- if(ricercaBinariaNonRicorsiva(arrPro, countPro, word) != -1)
- good = true;
- if(ricercaBinariaNonRicorsiva(arrCon, countCon, word) != -1)
- bad = true;
- if(bad && good)
- break;
- }
- if(bad && !good)
- badWords++;
- else if(!bad && good)
- goodWords++;
- }
- cout << badWords << " " << goodWords;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement