Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <algorithm>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int ricercaBinariaNonRicorsiva(string lista[], int n, string x)
  11. {
  12. int p, u, m;
  13. p = 0;
  14. u = n - 1;
  15. while(p <= u) {
  16. m = (p + u) / 2;
  17. if(lista[m] == x)
  18. return m; // valore x trovato alla posizione m
  19. if(lista[m] < x)
  20. p = m + 1;
  21. else
  22. u = m - 1;
  23. }
  24. // se il programma arriva a questo punto vuol dire che
  25. // il valore x non รจ presente in lista, ma se ci fosse
  26. // dovrebbe trovarsi alla posizione p (nota che qui p > u)
  27. return -1;
  28. }
  29.  
  30. int main()
  31. {
  32. freopen("input.txt", "r", stdin); // redirects standard input
  33. freopen("output.txt", "w", stdout);
  34.  
  35. int countPro, countCon;
  36. cin >> countCon;
  37.  
  38. string arrCon[countCon];
  39.  
  40. for(int i = 0; i < countCon; i++)
  41. cin >> arrCon[i];
  42.  
  43. sort(arrCon, arrCon + countCon);
  44.  
  45.  
  46. cin >> countPro;
  47. string arrPro[countPro];
  48. for(int i = 0; i < countPro; i++)
  49. cin >> arrPro[i];
  50.  
  51.  
  52. sort(arrPro, arrPro + countPro);
  53.  
  54. int f;
  55. cin >> f;
  56.  
  57. int goodWords = 0, badWords = 0;
  58.  
  59. for(int i = 0; i < f; i++)
  60. {
  61. int g;
  62. cin >> g;
  63.  
  64. bool bad = false, good = false;
  65. string word;
  66.  
  67. for(int j = 0; j < g; j++)
  68. {
  69. // usa j
  70. cin >> word;
  71.  
  72. if(ricercaBinariaNonRicorsiva(arrPro, countPro, word) != -1)
  73. good = true;
  74.  
  75.  
  76. if(ricercaBinariaNonRicorsiva(arrCon, countCon, word) != -1)
  77. bad = true;
  78.  
  79. if(bad && good)
  80. break;
  81.  
  82. }
  83.  
  84. if(bad && !good)
  85. badWords++;
  86. else if(!bad && good)
  87. goodWords++;
  88. }
  89.  
  90. cout << badWords << " " << goodWords;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement