Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
using namespace std;

//
// ???????????\\???????????????????????????????????????????????????????????????????????\\??????????????????????????????
//

#define m 1046527
#define l 14

char H[m][l];

int h1(long long key) { return key % m; }

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

int Hash(long long key, int i) {
  // double hash function using the above
  return (h1(key) + i * h2(key)) % m;
}

long long power(int x, int y) {
  if (y == 0)
    return 1;
  else
    return x * power(x, y - 1);
}

long long strtoi(char x[]) {
  long long sum = 0;
  for (unsigned int i = 0; i < strlen(x); i++) {
    if (x[i] == 'A')
      sum += 1 * power(10, i);
    else if (x[i] == 'C')
      sum += 2 * power(10, i);
    else if (x[i] == 'G')
      sum += 3 * power(10, i);
    else if (x[i] == 'T')
      sum += 4 * power(10, i);
  }
  return sum;
}

int insert(char str[]) {
  // insert data into the hash table
  long long i = 0;
  long long key = strtoi(str);
  while (true) {
    long long j = Hash(key, i);
    if (strcmp(H[j], str) == 0)
      return 1;
    else if (strlen(H[j]) == 0) {
      strcpy(H[j], str);
      return 0;
    } else
      i++;
  }
}

int search(char str[]) {
  // search data in the hash table
  long long i = 0;
  long long key = strtoi(str);
  while (true) {
    long long j = Hash(key, i);
    if (strcmp(H[j], str) == 0)
      return j;
    else if (strlen(H[j]) == 0)
      return 0;
    else
      i++;
  }
  return 0;
}

int main() {

  long long n;
  scanf("%lld", &n);

  char com[9];
  char str[l];

  for (int i = 0; i < m; i++) {
    H[i][0] = '\\0';
  }

  for (long long i = 0; i < n; i++) {
    scanf("%s%s", com, str);

    if (com[0] == 'i')
      insert(str);
    else if (com[0] == 'f') {
      if (search(str))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;

int m = 1046527;
int h1(int key) {
  // hash function 1
  return key % m;
}

int h2(int key) {
  // hash function 2
  return 1 + (key % m - 1);
}

int H(int key, int i) {
  // double hash function using the above
  return (h1(key) + i * h2(key)) % m;
}

int insert(long long T[], long long key) {
  // insert data into the hash table
  int i = 0;
  while (true) {
    int j = H(key, i);
    if (T[j] != 'A' || T[j] != 'C' || T[j] != 'G' || T[j] != 'T') {
      T[j] = key;
      return j;
    } else
      i++;
  }
}

int search(long long T[], long long key) {
  // search data in the hash table
  int i = 0;
  while (true) {
    int j = H(key, i);
    if (T[j] == key)
      return j;
    else if (T[j] != 'A' || T[j] != 'C' || T[j] != 'G' || T[j] != 'T' || i >= m)
      return 0;
    else
      i++;
  }
}

int power(int x, int y) {
  if (y == 0)
    return 1;
  else
    return x * power(x, y - 1);
}

long long strtoi(char x[]) {
  long long sum = 0;
  for (int i = 0; i < strlen(x); i++) {
    if (x[i] == 'A')
      sum += 1 * power(10, i);
    else if (x[i] == 'C')
      sum += 2 * power(10, i);
    else if (x[i] == 'G')
      sum += 3 * power(10, i);
    else if (x[i] == 'T')
      sum += 4 * power(10, i);
  }
  return sum;
}

int main() {

  int n;
  char com[10];
  char str[15];
  long long T[1000000];
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s%s", com, str);
    if (com[0] == 'i')
      insert(T, strtoi(str));
    else if (com[0] == 'f') {
      if (search(T, strtoi(str)))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
}