alexjercan/bugnet huggingface dataset:
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
char num1[10000000] = {0}, num11[10000000] = {0}, num2[10000000] = {0},
     b[10000000] = {0};
int main(void) {
  int n1 = 0, n2 = 0;
  int i, j, k;
  while (scanf("%d", &n1) != EOF) {
    if (n1 == 0)
      break;
    // fflush(stdin);
    getchar();
    for (i = 0; i < n1; i++) {
      // fflush(stdin);
      // getchar();
      scanf("%[^\\n]", b);
      num1[i] = b[0];
      num11[i] = b[2];
      b[0] = '\\0';
      b[1] = '\\0';
      b[2] = '\\0';
      // fflush(stdin);
      getchar();
    }
    // fflush(stdin);
    // printf("ok3\\n");
    // getchar();
    scanf("%d", &n2);
    for (i = 0; i < n2; i++) {
      // printf("ok4\\n");
      // fflush(stdin);
      scanf("%s", b);
      num2[i] = b[0];
      b[0] = '\\0';
      // fflush(stdin);
      getchar();
    }
    for (i = 0; i < n2; i++) {
      // printf("ng");
      if (num2[i] != 9999) {
        for (j = 0; j < n1; j++) {
          if (num2[i] == num1[j]) {
            // printf("%c = %c\\n",num2[i],num11[j]);
            num2[i] = num11[j];
            // printf("\\n%c = %c\\n",num2[i],num11[j]);
            break;
          }
        }
      }
    }
    // printf("%c\\n",num2[3]);
    for (i = 0; i < 10000000; i++) {
      if (num2[i] != '\\0')
        printf("%c", num2[i]);
      num1[i] = '\\0';
      num11[i] = '\\0';
      num2[i] = '\\0';
    }
    printf("\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
char num1[10000000] = {0}, num11[10000000] = {0}, num2[10000000] = {0},
     b[10000000] = {0};
int main(void) {
  int n1 = 0, n2 = 0;
  int i, j, k;
  while (scanf("%d", &n1) != EOF) {
    if (n1 == 0)
      break;
    fflush(stdin);
    for (i = 0; i < n1; i++) {
      // fflush(stdin);
      scanf("%[^\\n]", b);
      num1[i] = b[0];
      num11[i] = b[2];
      b[0] = '\\0';
      b[1] = '\\0';
      b[2] = '\\0';
      fflush(stdin);
    }
    fflush(stdin);
    // printf("ok3\\n");
    scanf("%d", &n2);
    for (i = 0; i < n2; i++) {
      // printf("ok4\\n");
      fflush(stdin);
      scanf("%s", b);
      num2[i] = b[0];
      b[0] = '\\0';
      fflush(stdin);
    }
    for (i = 0; i < n2; i++) {
      // printf("ng");
      if (num2[i] != 9999) {
        for (j = 0; j < n1; j++) {
          if (num2[i] == num1[j]) {
            // printf("%c = %c\\n",num2[i],num11[j]);
            num2[i] = num11[j];
            // printf("\\n%c = %c\\n",num2[i],num11[j]);
            break;
          }
        }
      }
    }
    // printf("%c\\n",num2[3]);
    for (i = 0; i < 100000000; i++) {
      if (num2[i] != '\\0')
        printf("%c", num2[i]);
      num1[i] = '\\0';
      num11[i] = '\\0';
      num2[i] = '\\0';
    }
    printf("\\n");
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {

  bool c;
  int i, n, num;
  char d, d1, d2;
  map<char, char> mp;

  while (cin >> n, n) {

    for (i = 0; i < n; i++) {
      cin >> d1 >> d2;
      mp.insert(make_pair(d1, d2));
    }

    cin >> n;

    for (i = 0; i < n; i++) {
      cin >> d;
      c = true;

      if (mp.find(d) != mp.end()) {
        pair<char, char> target = *mp.find(d);
        cout << target.second;
        c = false;
      }

      if (c)
        cout << d;
    }

    cout << endl;
    mp.clear();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  int i, n, num;
  bool c;
  char m, data[5][2];

  while (cin >> n, n) {

    for (i = 0; n--; i++)
      cin >> data[i][0] >> data[i][1];
    num = i;

    cin >> n;

    for (i = 0; i < n; i++) {
      cin >> m;
      c = true;
      for (int j = 0; j < num; j++) {
        if (data[j][0] == m) {
          cout << data[j][1];
          c = false;
          break;
        }
      }
      if (c)
        cout << m;
    }

    cout << endl;
  }

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

#include <iostream>

using namespace std;

int main() {
  int n, m;
  int data[128];
  char x, y;
  char z;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    else {
      for (int i = 0; i < 128; i++) {
        data[i] = i;
      }
      for (int i = 0; i < n; i++) {
        cin >> x >> y;
        data[static_cast<int>(x)] = static_cast<int>(y);
      }

      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> z;
        cout << static_cast<char>(data[static_cast<int>(z)]);
      }
      cout << "\\n";
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m;
  int data[128];
  char x, y;
  char z;
  cin >> n;
  while (n > 0) {
    for (int i = 0; i < 128; i++) {
      data[i] = i;
    }
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      data[(int)x] = (int)y;
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> z;
      cout << static_cast<char>(data[(int)z]);
    }
    cout << "\\n";
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    vector<char> v1, v2;
    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;
      v1.push_back(c);
      cin >> c;
      v2.push_back(c);
    }

    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      char b;
      cin >> b;
      for (int j = 0; j < n; j++) {
        if (b == v1[j]) {
          b = v2[j];
          break;
        }
      }

      cout << b;
    }

    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    char a[1000], a2[1000];
    for (int i = 0; i < n; i++)
      cin >> a[i] >> a2[i];

    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int b;
      cin >> b;
      for (int j = 0; j < n; j++)
        if (b == a[j])
          b = a2[j];

      cout << b;
    }

    cout << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
char v[256];
int n, m;
int main() {
  while (true) {
    cin >> n;
    for (int i = 32; i < 127; i++) {
      v[i] = i;
    }
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      char p, q;
      cin >> p >> q;
      v[p] = q;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      char f;
      cin >> f;
      cout << v[f];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
char v[256];
int n, m;
int main() {
  while (true) {
    cin >> n;
    for (int i = 32; i < 127; i++) {
      v[i] = i;
    }
    for (int i = 0; i < n; i++) {
      char p, q;
      cin >> p >> q;
      v[p] = q;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      char f;
      cin >> f;
      cout << v[f];
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, m;
  char c;
  pair<char, char> data[10000];
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int i = 0; i < n; i++)
      cin >> data[i].first >> data[i].second;
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> c;
      for (int j = 0; j < n; j++)
        if (data[j].first == c) {
          c = data[j].second;
          break;
        }
      cout << c;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, m;
  char c, ans[10000];
  pair<char, char> data[10000];
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int i = 0; i < n; i++)
      cin >> data[i].first >> data[i].second;
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> c;
      for (int j = 0; j < n; j++)
        if (data[j].first == c) {
          c = data[j].second;
          break;
        }
      ans[i] = c;
    }
    for (int i = 0; i < m; i++)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <stdio.h>

std::map<char, char> hyou;

bool init() {
  hyou.clear();
  int n;
  std::cin >> n;
  if (n == 0)
    return false;
  for (int i = 0; i < n; i++) {
    char c, d;
    std::cin >> c >> d;
    hyou[c] = d;
  }
  return true;
}

void solve() {
  char dust[500];
  int n;
  std::cin >> n;
  std::cin.getline(dust, sizeof(dust));
  for (int i = 0; i < n; i++) {
    char out;
    out = (char)getchar();
    if (hyou.find(out) != hyou.end())
      out = hyou[out];
    putchar((int)out);
    std::cin.getline(dust, sizeof(dust));
  }
  std::cout << std::endl;

  return;
}

int main(void) {
  while (init())
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <stdio.h>

std::map<char, char> hyou;

bool init() {
  hyou.clear();
  int n;
  std::cin >> n;
  if (n == 0)
    return false;
  for (int i = 0; i < n; i++) {
    char c, d;
    std::cin >> c >> d;
    hyou[c] = d;
  }
  return true;
}

void solve() {
  int n;
  std::cin >> n;
  n = getchar();
  for (int i = 0; i < n; i++) {
    char out;
    out = (char)getchar();
    if (hyou.find(out) != hyou.end())
      out = hyou[out];
    putchar((int)out);
    out = (char)getchar();
  }
  std::cout << std::endl;

  return;
}

int main(void) {
  while (init())
    solve();
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  while (1) {
    char d;
    char ans[101000];
    char f[1010000], g[101000];
    int n;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> d;
      f[i] = d;
      cin >> d;
      g[i] = d;
    }
    int s;
    cin >> s;
    for (int i = 0; i < s; i++) {
      cin >> d;
      ans[i] = d;
      for (int j = 0; j < n; j++) {
        if (ans[i] == f[j]) {
          ans[i] = g[j];
          break;
        }
      }
    }
    for (int i = 0; i < s; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (1) {
    char d;
    char ans[101];
    char f[101], g[101];
    int n;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> d;
      f[i] = d;
      cin >> d;
      g[i] = d;
    }
    int s;
    cin >> s;
    for (int i = 0; i < s; i++) {
      cin >> d;
      ans[i] = d;
      for (int j = 0; j < n; j++) {
        if (ans[i] == f[j]) {
          ans[i] = g[j];
          break;
        }
      }
    }
    for (int i = 0; i < s; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  char tmp;
  string ans = "";

  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vector<char> before(n);
    vector<char> after(n);
    for (int i = 0; i < n; ++i) {
      cin >> before[i];
      cin >> after[i];
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tmp;
      for (int j = 0; j < n; ++j) {
        if (tmp == before[j]) {
          tmp = after[j];
          break;
        }
      }
      ans += tmp;
    }

    cout << ans << endl;

    ans = "";
    before.clear();
    after.clear();
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid


Fixed submission:

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

int main() {
  int n, m;
  char tmp;
  string ans = 0;
  vector<int> before(0);
  vector<int> after(0);

  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; ++i) {
      before.push_back(i);
      after.push_back(i);
      cin >> before[i];
      cin >> after[i];
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tmp;
      if (tmp == before[i])
        tmp = after[i];
      ans += tmp;
    }

    cout << ans << endl;

    ans = "";
    before.clear();
    after.clear();
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  char dic[100000][2] = {};
  char m[100000] = {};
  int i = 0, ii = 0, j = 0;
  int foo = 1;
  int n, mn;
  unsigned char tem, memo;
  while (ii < 5) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      for (j = 0; j < 2; j++) {
        cin >> dic[i][j];
      }
    }
    // cout<<dic[1][0]<<dic[1][1]<<endl;
    cin >> mn;
    for (i = 0; i < mn; i++) {
      cin >> m[i];
    }
    for (i = 0; i < mn; i++) {
      for (j = 0; j < n; j++) {

        if (m[i] == dic[j][0]) {
          m[i] = dic[j][1];
          foo = 1;
        }
        if (foo == 1)
          break;
      }
      foo = 0;
    }
    for (i = 0; i < mn; i++) {
      cout << m[i];
    }
    cout << endl;
    // foo=0;
    ii++;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  unsigned char dic[1000][2];
  unsigned char m[1000];
  int i = 0, ii = 0, j = 0;
  int n, mn;
  while (ii < 5) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      for (j = 0; j < 2; j++) {
        cin >> dic[i][j];
      }
    }
    // cout<<dic[1][0]<<dic[1][1]<<endl;
    cin >> mn;
    for (i = 0; i < mn; i++) {
      cin >> m[i];
    }
    for (i = 0; i < mn; i++) {
      for (j = 0; j < n; j++) {
        if (m[i] == dic[j][0]) {
          m[i] = dic[j][1];
        }
      }
    }
    m[3] = '5';
    for (i = 0; i < 100; i++) {
      cout << m[i];
    }
    cout << endl;
    ii++;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  while (1) {
    int n;
    map<string, string> table;
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      string src, dest;
      cin >> src >> dest;
      table[src] = dest;
    }

    cin >> n;
    vector<string> seq;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (table.find(s) == table.end()) {
        cout << s << flush;
      } else {
        cout << table[s] << flush;
      }
    }
    cout << endl;
  }

  return EXIT_SUCCESS;
}

Error: TLE

Fixed submission:

#include <cstdio>
#define MAX 100000000

struct cpair {
  char before;
  char after;
};

typedef struct cpair pair;
pair p[MAX];

int main() {
  int n, m, c;
  while (1) {

    scanf("%d%*c", &n);
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      scanf("%c%*c%c%*c", &p[i].before, &p[i].after);
      /*
            p[ i ].before = getchar();
            getchar();
            p[ i ].after = getchar();
            getchar();
      */
    }

    scanf("%d%*c", &m);
    //   getchar();
    for (int i = 0; i < m; i++) {
      char c;
      scanf("%c%*c", &c);
      //      char c = getchar();
      //      getchar();
      int j;
      for (j = 0; j < n; j++) {
        if (c == p[j].before) {
          putchar(p[j].after);
          break;
        }
      }
      if (j == n) {
        putchar(c);
      }
    }
    putchar('\\n');
  }

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

#include <stdio.h>

int main() {
  int c[256];
  int a;
  while (1) {
    scanf("%d", &a);
    if (a == 0)
      return 0;
    for (int i = 0; i < 256; i++)
      c[i] = i;
    getchar();
    getchar();
    for (int i = 0; i < a; i++) {
      char b, d;
      b = getchar();
      getchar();
      d = getchar();
      getchar();
      getchar();
      c[b] = d;
    }
    int e;
    scanf("%d", &e);
    getchar();
    getchar();
    char f;
    for (int i = 0; i < e; i++) {
      f = getchar();
      getchar();
      getchar();
      putchar(c[(int)f]);
    }
    printf("\\n");
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int c[256];
  int a;
  while (1) {
    scanf("%d", &a);
    if (a == 0)
      return 0;
    for (int i = 0; i < 256; i++)
      c[i] = i;
    getchar();
    for (int i = 0; i < a; i++) {
      char b, d;
      b = getchar();
      getchar();
      d = getchar();
      getchar();
      c[b] = d;
    }
    int e;
    scanf("%d", &e);
    getchar();
    char f;
    for (int i = 0; i < e; i++) {
      f = getchar();
      getchar();
      putchar(c[(int)f]);
    }
    printf("\\n");
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

char a[100][2];

int main() {
  int n, m;
  while (n = in()) {
    int i;
    for (i = 0; i < n; i++) {
      cin >> a[i][0] >> a[i][1];
    }
    m = in();
    for (i = 0; i < m; i++) {
      char ch;
      int j;
      cin >> ch;
      for (j = 0; j < n; j++) {
        if (a[j][0] == ch) {
          cout << a[j][1];
          break;
        }
      }
      if (j == n)
        cout << ch;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

char a[100][2];

int main() {
  int n, m;
  while (n = in()) {
    int i;
    for (i = 0; i < n; i++) {
      cin >> a[i][0] >> a[i][1];
    }
    m = in();
    for (i = 0; i < m; i++) {
      char ch;
      int j;
      cin >> ch;
      for (j = 0; j < m; j++) {
        if (a[j][0] == ch) {
          cout << a[j][1];
          break;
        }
      }
      if (j == m)
        cout << ch;
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  char table[100000][2];
  long int n, m, i, c;
  char buf;
  while (scanf("%ld", &n)) {
    if (n == 0)
      break;
    for (i = 0; n > i; i++) {
      getchar();
      scanf("%c", &table[i][0]);
      getchar();
      scanf("%c", &table[i][1]);
    }
    scanf("%ld", &m);
    for (i = 0; m > i; i++) {
      getchar();
      scanf("%c", &buf);
      for (c = 0; n > c; c++)
        if (buf == table[c][0]) {
          buf = table[c][1];
          break;
        }
      printf("%c", buf);
    }
    printf("\\n");
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main(void) {
  char table[5][2];
  int n, m, i, c;
  char buf;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    for (i = 0; n > i; i++) {
      getchar();
      scanf("%c", &table[i][0]);
      getchar();
      scanf("%c", &table[i][1]);
    }
    scanf("%d", &m);
    for (i = 0; m > i; i++) {
      getchar();
      scanf("%c", &buf);
      for (c = 0; n > c; c++)
        if (buf == table[c][0]) {
          buf = table[c][1];
          break;
        }
      printf("%c", buf);
    }
    printf("\\n");
  }

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

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

int main() {
  map<char, char> mp;
  char a, b, c;
  string x;
  int n;
  cin >> n;
  do {
    mp.clear();
    x.clear();
    do {
      cin >> a >> b;
      mp[a] = b;
    } while (--n);

    cin >> n;
    do {
      cin >> c;
      if (mp[c] != NULL) {
        x += mp[c];
      } else {
        x += c;
      }
    } while (--n);
    cout << x << endl;
  } while (cin >> n, n != 0);

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  map<char, char> mp;
  char a, b, c;
  string x;
  int n;
  cin >> n;
  do {
    mp.clear();
    n = 0;
    x.clear();
    do {
      cin >> a >> b;
      mp[a] = b;
    } while (--n);

    cin >> n;
    do {
      cin >> c;
      if (mp[c] != NULL) {
        x += mp[c];
      } else {
        x += c;
      }
    } while (--n);
    cout << x << endl;
  } while (cin >> n, n != 0);

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

#include <stdio.h>

int main() {
  int n, m, i, j;
  char nn[1000000], nm[1000000], mm[1000000];
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    for (i = 0; i < n; i++) {
      scanf(" %c %c", &nn[i], &nm[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf(" %c", &mm[i]);
      for (j = 0; j < n; j++)
        if (mm[i] == nn[j]) {
          mm[i] = nm[j];
          break;
        }
    }
    puts(mm);
  }
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int n, m, i, j;
  char nn[99999999], nm[99999999], mm[99999999];
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    for (i = 0; i < n; i++) {
      scanf(" %c %c", &nn[i], &nm[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf(" %c", &mm[i]);
      for (j = 0; j < n; j++)
        if (mm[i] == nn[j]) {
          mm[i] = nm[j];
          break;
        }
    }
    puts(mm);
  }
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

using namespace std;

char conv[256];
int n, m;

int main() {
  char c;
  char s1[2];
  char s2[2];
  while (scanf("%d", &n) && n) {
    for (int i = 0; i < 256; i++) {
      conv[i] = i;
    }
    for (int i = 0; i < n; i++) {
      scanf("%s %s", s1, s2);
      conv[*s1] = *s2;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%s", s1);
      printf("%c", conv[*s1]);
    }
    printf("\\n");
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <map>

using namespace std;

char getc() {
  char c;
  while (1) {
    if (scanf("%c", &c) == EOF) {
      return 0;
    }
    if (c != ' ' && c != '\\n') {
      break;
    }
  }
  return c;
}

int main() {
  int n, m;
  char a, b;
  char c;
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    char conv[256];
    for (c = 'a'; c <= 'z'; c++) {
      conv[c] = c;
    }
    for (c = 'A'; c <= 'Z'; c++) {
      conv[c] = c;
    }
    for (c = '0'; c <= '9'; c++) {
      conv[c] = c;
    }
    for (int i = 0; i < n; i++) {
      a = getc();
      b = getc();
      conv[a] = b;
      // printf("%c->%c\\n",a,b);
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      c = getc();
      printf("%c", conv[c]);
    }
    printf("\\n");
  }
}