fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. std::map<long long int, int> libri;
  5. using namespace std;
  6.  
  7. // Declaring functions
  8. void aggiungi(long long int id);
  9. void togli(long long int id);
  10. int conta(long long int id);
  11.  
  12. void aggiungi(long long int id) {
  13. libri[id]++;
  14. }
  15.  
  16. void togli(long long int id) {
  17. if(libri[id] > 0){
  18. libri[id]--;
  19. if(libri[id] == 0){
  20. libri.erase(id);
  21. }
  22. }
  23. }
  24.  
  25. int conta(long long int id) {
  26. return libri[id];
  27. }
  28.  
  29.  
  30. int main() {
  31. ios::sync_with_stdio(false);
  32.  
  33. // Uncomment the following lines if you want to read/write from files
  34. // ifstream cin("input.txt");
  35. // ofstream cout("output.txt");
  36.  
  37. int Q;
  38. cin >> Q;
  39.  
  40. for(int i = 0; i < Q; i++){
  41. char t;
  42. long long int id;
  43. cin >> t >> id;
  44.  
  45. if(t == 'a') {
  46. aggiungi(id);
  47. } else if (t == 't') {
  48. togli(id);
  49. } else if (t == 'c') {
  50. cout << conta(id) << '\n';
  51. }
  52. }
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
a 5
c 7
a 10
a 5
c 5


stdout
0
2