fork(1) download
  1. symbol table
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. class Symbol_table {
  7. set<pair<string, string>> v[10];
  8. public:
  9. int hashfun(string name) {
  10. int sum = 0;
  11. for(int i = 0; i < name.size(); i++) {
  12. sum += name[i];
  13. }
  14. return sum % 10;
  15. }
  16.  
  17. void insertt(string name, string type) {
  18.  
  19. int hash_val = hashfun(name);
  20. set<pair<string, string>> se = v[hash_val];
  21.  
  22. if(se.find({name, type}) == se.end()) {
  23. v[hash_val].insert({name, type});
  24. cout << "successful insertion\n";
  25. }
  26. else {
  27. cout << "Already inserted\n";
  28. }
  29. }
  30.  
  31. void deletee(string name, string type) {
  32.  
  33. int hash_val = hashfun(name);
  34. set<pair<string, string>> se = v[hash_val];
  35.  
  36. if(se.find({name, type}) != se.end()) {
  37. v[hash_val].erase({name, type});
  38. cout << "Successful deletion\n";
  39. }
  40. else {
  41. cout << "Nai\n";
  42. }
  43. }
  44.  
  45. void lookup(string name, string type) {
  46.  
  47. int hash_val = hashfun(name);
  48. set<pair<string, string>> se = v[hash_val];
  49.  
  50. if(se.find({name, type}) == se.end()) {
  51. cout << "0\n";
  52. }
  53. else {
  54. cout << "1\n";
  55. }
  56. }
  57.  
  58. void print() {
  59. for(auto se : v) {
  60. for(auto p : se) {
  61. cout << p.first << " " << p.second << '\n';
  62. }
  63. }
  64. }
  65. };
  66.  
  67. int main() {
  68. ios_base::sync_with_stdio(false);
  69. cin.tie(NULL);
  70.  
  71. Symbol_table s;
  72. s.insertt("int", "id");
  73. s.insertt("int", "id");
  74. s.deletee("yoyo", "fifa");
  75. s.print();
  76. // s.deletee("int", "id");
  77. s.lookup("int", "id");
  78. s.insertt("bool", "float");
  79. s.deletee("bool", "float");
  80. s.print();
  81. return 0;
  82. }-- your code goes here
Success #stdin #stdout #stderr 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "symbol": syntax error
Error: near line 6: near "class": syntax error
Error: near line 8: near "public": syntax error
Error: near line 11: near "for": syntax error
Error: near line 13: unrecognized token: "}"
Error: near line 15: unrecognized token: "}"
Error: near line 20: near "set": syntax error
Error: near line 22: near "if": syntax error
Error: near line 24: near "cout": syntax error
Error: near line 25: unrecognized token: "}"
Error: near line 28: unrecognized token: "}"
Error: near line 34: near "set": syntax error
Error: near line 36: near "if": syntax error
Error: near line 38: near "cout": syntax error
Error: near line 39: unrecognized token: "}"
Error: near line 42: unrecognized token: "}"
Error: near line 48: near "set": syntax error
Error: near line 50: near "if": syntax error
Error: near line 52: unrecognized token: "}"
Error: near line 55: unrecognized token: "}"
Error: near line 62: unrecognized token: "}"
Error: near line 67: near "int": syntax error
Error: near line 69: near "cin": syntax error
Error: near line 71: near "Symbol_table": syntax error
Error: near line 72: near "s": syntax error
Error: near line 73: near "s": syntax error
Error: near line 74: near "s": syntax error
Error: near line 75: near "s": syntax error
Error: near line 76: near "/": syntax error
Error: near line 77: near "s": syntax error
Error: near line 78: near "s": syntax error
Error: near line 79: near "s": syntax error
Error: near line 80: near "s": syntax error
Error: near line 81: near "return": syntax error
Error: near line 82: unrecognized token: "}"