fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> ss;
  6. vector<int> x;
  7. int sum = 0, warn = 0;
  8.  
  9. bool avaliable(string s) {
  10. for (int i = 0; i < (int)ss.size(); ++i)
  11. if (s == ss[i])
  12. return true;
  13. return false;
  14. }
  15.  
  16. int finde(string s) {
  17. for (int i = 0; i < (int)ss.size(); ++i)
  18. if (s == ss[i])
  19. return i;
  20. }
  21.  
  22. int main()
  23. {
  24. int n, indx;
  25. string s;
  26. cin >> n;
  27. for (int i = 0; i < n; ++i) {
  28. cin >> s;
  29. if (!avaliable(s)) {
  30. ss.push_back(s);
  31. x.push_back(1);
  32. ++sum;
  33. } else {
  34. indx = finde(s);
  35. if (x[indx] > sum - x[indx])
  36. ++warn;
  37. ++x[indx], ++sum;
  38. }
  39. }
  40.  
  41. cout << warn;
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 3420KB
stdin
17
a
b
b
a
a
a
c
a
b
b
c
b
b
b
b
b
b
stdout
4