alexjercan/bugnet huggingface dataset:
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

int main() {
  int n;

  cin >> n;

  set<string> s;
  set<string>::iterator it;
  char query[5];
  string str;

  for (int i = 0; i < n; i++) {
    scanf("%s", query);
    if (query[0] == 'i') {
      cin >> str;
      s.insert(str);
    } else {
      cin >> str;
      it = s.find(str);
      if (it == s.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
using namespace std;

int main() {
  int n;

  cin >> n;

  set<string> s;
  set<string>::iterator it;
  string query, str;

  for (int i = 0; i < n; i++) {
    cin >> query >> str;
    if (query == "insert")
      s.insert(str);
    else {
      it = s.find(str);
      if (it == s.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }

  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;

#define M 1000000
#define NIL (-1)
#define L 14

char H[M][L];

long long getkey(char *str) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    switch (str[i]) {
    case 'A':
      sum += 0 * p;
      break;
    case 'C':
      sum += 1 * p;
      break;
    case 'G':
      sum += 2 * p;
      break;
    case 'T':
      sum += 3 * p;
      break;
    default:
      break;
    }
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }

int h2(int key) { return 1 + (key % (M - 1)); }

int find(char *str) {
  long long key, i, h;
  key = getkey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int insert(char *str) {
  long long key, i, h;
  key = getkey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int n, h;
  char str[L], com[9];
  for (int i = 0; i < M; i++) {
    H[i][0] = '\\0';
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com;
    cin >> str;
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        cout << "yes\\n";
      } else {
        cout << "no\\n";
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;

#define M 1000000
#define NIL (-1)
#define L 14

char H[M][L];

long long getkey(char *str) {
  int sum = 0;
  for (int i = 0; i < strlen(str); i++) {
    switch (str[i]) {
    case 'A':
      sum += 0 * pow(10, i);
      break;
    case 'C':
      sum += 1 * pow(10, i);
      break;
    case 'G':
      sum += 2 * pow(10, i);
      break;
    case 'T':
      sum += 3 * pow(10, i);
      break;
    default:
      break;
    }
  }
  return sum;
}

int h1(int key) { return key % M; }

int h2(int key) { return 1 + (key % (M - 1)); }

int find(char *str) {
  long long key, i, h;
  key = getkey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int insert(char *str) {
  long long key, i, h;
  key = getkey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int n, h;
  char str[L], com[9];
  for (int i = 0; i < M; i++) {
    H[i][0] = '\\0';
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com;
    cin >> str;
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        cout << "yes\\n";
      } else {
        cout << "no\\n";
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

class Element {
public:
  string value;
  Element *left;
  Element *right;

  Element() : value(""), left(NULL), right(NULL) {}
};

void insert(Element *dict, string s) {
  if (dict == NULL) {
    dict = new Element;
    dict->value = s;
  } else {
    Element *new_elem = new Element;
    new_elem->value = s;

    Element *elem = dict;
    while (true) {
      if (elem->value > s) {
        if (elem->left == NULL) {
          elem->left = new_elem;
          break;
        }
        elem = elem->left;
      } else {
        if (elem->right == NULL) {
          elem->right = new_elem;
          break;
        }
        elem = elem->right;
      }
    }
  }
}

void delete_dict(Element *dict) {
  if (dict == NULL)
    return;

  delete_dict(dict->left);
  delete_dict(dict->right);
  delete dict;
}

Element *find(Element *dict, string s) {
  Element *elem = dict;
  while (true) {
    if (elem == NULL)
      break;

    if (elem->value == s)
      return elem;
    else if (elem->value > s)
      elem = elem->left;
    else
      elem = elem->right;
  }
  return NULL;
}

int main() {
  ios::sync_with_stdio(false);

  Element *dict = new Element;

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string op, value;
    cin >> op >> value;

    if (op == "insert") {
      insert(dict, value);
    } else {
      Element *e = find(dict, value);
      if (e != NULL)
        cout << "yes\\n";
      else
        cout << "no\\n";
    }
  }

  delete_dict(dict);
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  int index = 0;
  vector<string> vec(n);
  for (int i = 0; i < n; ++i) {
    string operation;
    cin >> operation;

    if (operation == "insert") {
      cin >> vec[index];
      ++index;
    } else {
      string key;
      cin >> key;

      bool flag = false;
      for (int j = 0; j < index; ++j) {
        if (vec[j] == key) {
          flag = true;
          break;
        }
      }

      if (flag)
        cout << "yes\\n";
      else
        cout << "no\\n";
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

int n;

int main() {
  map<string, bool> d;
  string q, s;
  scanf("%d ", &n);
  for (int i = 0; i < n; i++) {
    char qq[7], ss[13];
    scanf("%s%s ", qq, ss);
    q = qq;
    s = ss;
    //    cin >> q >> s;
    //    if (q == "insert" && !d.count(s))
    if (q == "insert")
      d[s] = true;
    else if (q == "find") {
      //      cout << (d.count(s) ? "yes" : "no") << endl;
      if (d.count(s))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

int n;

int main() {
  map<string, bool> d;
  string q, s;
  scanf("%d ", &n);
  for (int i = 0; i < n; i++) {
    cin >> q >> s;
    //    if (q == "insert" && !d.count(s))
    if (q == "insert")
      d[s] = true;
    else if (q == "find") {
      //      cout << (d.count(s) ? "yes" : "no") << endl;
      if (d.count(s))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(void) {
  int n;
  char order[8], str[16];
  map<string, bool> dict;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", order, str);
    if (order[0] == 'i') {
      dict[string(str)] = true;
    } else {
      if (dict[string(str)]) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(void) {
  int n;
  string order, str;
  map<string, bool> dict;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> order >> str;
    if (order[0] == 'i') {
      dict[str] = true;
    } else {
      if (dict[str]) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  int N;
  string str, s;
  cin >> N;
  map<string, bool> dictionary;
  for (int i = 0; i < N; i++) {
    cin >> str >> s;
    if (str == "insert") {
      dictionary[s] = true;
    } else {
      if (dictionary[s])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <string>
using namespace std;
bool search(string str, queue<string> dictionary) {
  dictionary.push(str);
  int l = 0;
  while (str != dictionary.front()) {
    dictionary.push(dictionary.front());
    dictionary.pop();
    l++;
  }
  bool sign = false;
  if (l < dictionary.size() - 1) {
    sign = true;
    for (int i = l; i < dictionary.size() - 1; i++) {
      dictionary.push(dictionary.front());
      dictionary.pop();
    }
    dictionary.pop();
  } else
    dictionary.pop();
  if (sign)
    return true;
  else
    return false;
}
int main() {
  int N;
  cin >> N;
  string instruction, str;
  queue<string> dictionary;
  for (int I = 0; I < N; I++) {
    cin >> instruction >> str;
    if (instruction == "insert") {
      dictionary.push(str);
    } else {
      if (search(str, dictionary))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  map<string, bool> T;
  int commandNum;

  cin >> commandNum;
  for (int i = 0; i < commandNum; i++) {
    string command, str;
    cin >> command >> str;

    if (command[0] == 'i')
      T[str] = true; // insert??????
    else {           // find??????
      if (T[str])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

const int MAX = 1000000;

int strToInt(string mes) {
  long long key;
  key = 0;
  for (int i = 0; i < mes.length(); i++) {
    if (mes[i] == 'A') {
      key += 1;
    } else if (mes[i] == 'C') {
      key += 2;
    } else if (mes[i] == 'G') {
      key += 3;
    } else if (mes[i] == 'T') {
      key += 4;
    } else {
      return 0;
    }
    key = key << 1;
  }
  return key;
}

int h1(int key) { return key % MAX; }

int h2(int key) { return 1 + (key % (MAX - 1)); }

void insertHash(string dic[], char message[]) {
  long long key;
  key = strToInt(message);
  int i = 0;
  while (true) {
    long long h = (h1(key) + i * h2(key)) % MAX;
    if (dic[h] == message) {
      return; //?????????????????§?????\\??£???????????????????????????
    } else if (dic[h] == "\\0") {
      dic[h] = message;
      return;
    } else {
      i++;
    }
  }
}

bool findHash(string dic[], char message[]) {
  long long key;
  key = strToInt(message);
  int i = 0;
  while (true) {
    long long h = (h1(key) + i * h2(key)) % MAX;
    if (dic[h] == message) {
      return true;
    } else if (dic[h] == "\\0") {
      return false; //\\0??¨???????????¨???????????????????????????????????????,
                    //??????????????£??????????????§????????????????????\\??£???????????????
    } else {
      i++;
    }
  }
  return false;
}

void dumpList(string answer[], int num) {
  for (int i = 0; i < num; i++) {
    printf("%s\\n", answer[i].c_str());
  }
}
int main() {
  //	const int MAX = 1000000+1;
  string dictionary[MAX];
  //	string answer[MAX];
  int num;
  //	int dicMaxPoint;
  int ansMaxPoint;
  //	dicMaxPoint = 0;
  ansMaxPoint = 0;
  for (int i = 0; i < MAX; i++) {
    dictionary[i] = "\\0";
  }
  //	cin >> num;
  scanf("%d", &num);

  for (int i = 0; i < num; i++) {
    string command;
    string message;
    char com[12];
    char mes[12];
    // cin >> command;
    // cin >> message;
    scanf("%s", com);
    scanf("%s", mes);
    //		command = com;
    //		message = mes;
    if (com[0] == 'i') {
      insertHash(dictionary, mes);
    } else {
      if (findHash(dictionary, mes)) {
        //				answer[ansMaxPoint++] = "yes";
        printf("yes\\n");
      } else {
        //				answer[ansMaxPoint++] = "no";
        printf("no\\n");
      }
    }
  }

  //	dumpList(answer, ansMaxPoint);
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

const int M = 1046527;

string H[M];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(string str) {
  long long sum = 0;
  int p = 1;
  for (int i = 0; i < str.length(); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
long long hfunc(long long key, int i) { return (h1(key) + i * h2(key)) % M; }

bool insert(string str) {
  int key;
  long long h;
  key = getKey(str);

  for (int i = 0;; i++) {
    h = hfunc(key, i);
    if (H[h].length() == 0) {
      H[h] = str;
      return true;
    } else if (i > M)
      return false;
  }
}

bool find(string str) {
  int key;
  long long h;
  key = getKey(str);
  h = key;

  for (int i = 0;; i++) {
    h = hfunc(key, i);
    if (H[h] == str)
      return true;
    else if (H[h].length() == 0)
      return false;
  }
}

int main() {
  int n;
  string cmd, obj;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> obj;
    if (cmd[0] == 'i')
      insert(obj);
    else if (cmd[0] == 'f')
      if (find(obj))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

const int M = 1046527;

string H[M];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(string str) {
  long long sum = 0;
  int p = 1;
  for (int i = 0; i < str.length(); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
long long hfunc(long long key, int i) { return (h1(key) + i * h2(key)) % M; }

bool insert(string str) {
  int key;
  long long h;
  key = getKey(str);
  h = key;
  for (int i = 0;; i++) {
    if (H[h].length() == 0) {
      H[h] = str;
      return true;
    } else if (H[h].length() > 0)
      h = hfunc(key, i);
    else if (i > M)
      return false;
  }
}

bool find(string str) {
  int key;
  long long h;
  key = getKey(str);
  h = key;

  for (int i = 0;; i++) {
    if (H[h] == str)
      return true;
    else if (H[h].length() > 0)
      h = hfunc(key, i);
    else if (H[h].length() == 0)
      return false;
  }
}

int main() {
  int n;
  string cmd, obj;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> obj;
    if (cmd[0] == 'i')
      insert(obj);
    else if (cmd[0] == 'f')
      if (find(obj))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
  }
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int NumStr(const string &str) {
  int n = str.size();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'A')
      sum += 1;
    else if (str[i] == 'C')
      sum += 2;
    else if (str[i] == 'G')
      sum += 3;
    else if (str[i] == 'T')
      sum += 4;
    sum *= 4;
  }
  return sum;
}

void InsertFlag(vector<bool> &flag, const string &str) {
  int num_str = NumStr(str);
  flag[num_str] = true;
}
void FindFlag(vector<bool> &flag, const string &str) {
  int num_str = NumStr(str);
  if (flag[num_str] == true)
    cout << "yes" << endl;
  else if (flag[num_str] == false)
    cout << "no" << endl;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<bool> flag;
  flag.resize(16777216);

  for (int i = 0; i < n; i++) {
    string command, str;
    cin >> command >> str;
    if (command == "insert")
      InsertFlag(flag, str);
    else if (command == "find")
      FindFlag(flag, str);
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int NumStr(const string &str) {
  int n = str.size();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'A')
      sum += 1;
    else if (str[i] == 'C')
      sum += 2;
    else if (str[i] == 'G')
      sum += 3;
    else if (str[i] == 'T')
      sum += 4;
    sum *= sum;
  }
  return sum;
}

void InsertFlag(vector<bool> &flag, const string &str) {
  int num_str = NumStr(str);
  flag[num_str] = true;
}
void FindFlag(vector<bool> &flag, const string &str) {
  int num_str = NumStr(str);
  if (flag[num_str] == true)
    cout << "yes" << endl;
  else if (flag[num_str] == false)
    cout << "no" << endl;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<bool> flag;
  flag.resize(444444444444);

  for (int i = 0; i < n; i++) {
    string command, str;
    cin >> command >> str;
    if (command == "insert")
      InsertFlag(flag, str);
    else if (command == "find")
      FindFlag(flag, str);
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

#define N 10000009
int ht[N];

void inserth(int x) {
  int h = x % N;
  for (;;) {
    if (ht[h] == -1) {
      ht[h] = x;
      break;
    } else {
      h = (h + 193) % N;
    }
  }
}

int find(int x) {
  int h = x % N;
  for (;;) {
    if (ht[h] == -1) {
      return 0;
    } else if (ht[h] == x) {
      return 1;
    } else {
      h = (h + 193) % N;
    }
  }
}

int getint(string &s) {
  int ret = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'A')
      ret += 1;
    if (s.at(i) == 'T')
      ret += 2;
    if (s.at(i) == 'G')
      ret += 3;
    if (s.at(i) == 'C')
      ret += 4;
    ret *= 5;
  }
  return ret;
}

int main() {
  for (int i = 0; i < N; i++)
    ht[i] = -1;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char s1_[10];
    char s2_[12];
    scanf("%s %s", s1_, s2_);
    string s1 = s1_;
    string s2 = s2_;
    if (s1 == "insert")
      inserth(getint(s2));
    if (s1 == "find") {
      if (find(getint(s2))) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

#define N 10000009
int ht[N];

void inserth(int x) {
  int h = x % N;
  for (;;) {
    if (ht[h] == -1) {
      ht[h] = x;
      break;
    } else {
      h++;
      if (h == N)
        h = 0;
    }
  }
}

int find(int x) {
  int h = x % N;
  for (;;) {
    if (ht[h] == -1) {
      return 0;
    } else if (ht[h] == x) {
      return 1;
    } else {
      h++;
      if (h == N)
        h = 0;
    }
  }
}

int getint(string &s) {
  int ret = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'A')
      ret += 1;
    if (s.at(i) == 'T')
      ret += 2;
    if (s.at(i) == 'G')
      ret += 3;
    if (s.at(i) == 'C')
      ret += 4;
    ret *= 5;
  }
  return ret;
}

int main() {
  for (int i = 0; i < N; i++)
    ht[i] = -1;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char s1_[10];
    char s2_[12];
    scanf("%s %s", s1_, s2_);
    string s1 = s1_;
    string s2 = s2_;
    if (s1 == "insert")
      inserth(getint(s2));
    if (s1 == "find") {
      if (find(getint(s2))) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string.h>

#define M 1046527 // It's a  "prime number".
#define L 14      // Why?

char H[M][L];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }

  return 0;
}

int main() {

  int n;
  scanf("%d", &n);

  char str[L], com[9];
  for (int i = 0; i < M; i++) {
    H[i][0] = '\\0';
  }
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
    } else if (com[0] == 'f') {
      if (find(str))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>

#define M 1046527 // It's a  "prime number".
#define L 14      // Why?

char H[M][L];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = h1(key) + i * h2(key);
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }

  return 0;
}

int main() {

  int n;
  scanf("%d", &n);

  char str[L], com[9];
  for (int i = 0; i < M; i++) {
    H[i][0] = '\\0';
  }
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
    } else if (com[0] == 'f') {
      if (find(str))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}