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

#include <iostream>
#include <string>
using namespace std;
int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    string bef;
    string aft;
    for (int i = 0; i < n; i++) {
      char a, b;
      cin >> a >> b;
      bef.push_back(a);
      aft.push_back(b);
    }
    int m;
    cin >> m;
    string s_bef;
    for (int i = 0; i < m; i++) {
      char a;
      cin >> a;
      s_bef.push_back(a);
      for (int j = 0; j < n; ++j) {
        if (s_bef[i] == bef[j]) {
          s_bef[i] = aft[j];
          break;
        }
      }
    }
    cout << s_bef << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    string bef;
    string aft;
    for (int i = 0; i < n; i++) {
      char a, b;
      cin >> a >> b;
      bef.push_back(a);
      aft.push_back(b);
    }
    int m;
    cin >> m;
    string s_bef;
    string s_aft;
    for (int i = 0; i < m; i++) {
      char a;
      cin >> a;
      s_bef.push_back(a);
      s_aft[i] = s_bef[i];
      for (int j = 0; j < n; j++) {
        if (s_bef[i] == bef[j]) {
          s_aft[i] = aft[j];
        }
      }
    }
    cout << s_aft << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
std::string r1[100], r2[100], s[1000000];
int main() {
  int n;
  int m;
  while (true) {
    std::cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      std::cin >> r1[i] >> r2[i];
    std::cin >> m;
    for (int i = 0; i < m; i++)
      std::cin >> s[i];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (r1[j] == s[i]) {
          s[i] = r2[j];
          goto p;
        }
      }
    p:;
    }
    for (int i = 0; i < m; i++) {
      if (i == m - 1)
        std::cout << s[i] << std::endl;
      else {
        std::cout << s[i];
      }
    }
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
std::string r1[100], r2[100], s[10000000];
int main() {
  int n;
  int m;
  while (true) {
    std::cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      std::cin >> r1[i] >> r2[i];
    std::cin >> m;
    for (int i = 0; i < m; i++)
      std::cin >> s[i];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (r1[j] == s[i]) {
          s[i] = r2[j];
          goto p;
        }
      }
    p:;
    }
    for (int i = 0; i < m; i++) {
      if (i == m - 1)
        std::cout << s[i] << std::endl;
      else {
        std::cout << s[i];
      }
    }
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

char out[100000 + 1];
char change[100000];

using namespace std;

int main(void) {
  char now, next;

  int n;
  while (1) {
    cin >> n;

    if (n == 0) {
      return 0;
    }

    memset(change, 0, sizeof change);
    memset(out, 0, sizeof out);

    int i;
    for (i = 0; i < n; ++i) {
      cin >> now;
      cin >> next;

      change[now] = next;
    }

    cin >> n;

    for (i = 0; i < n; ++i) {
      cin >> now;

      out[i] = change[now] == '\\0' ? now : change[now];
    }

    cout << out << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int n, m, i, j;
  char h[3][3], d[10000 + 1];

  cin >> n;
  while (n != 0) {
    fo(i, n) { cin >> h[i][0] >> h[i][1]; }
    cin >> m;
    fo(i, m) {
      cin >> d[i];
      fo(j, n) {
        if (d[i] == h[j][0]) {
          d[i] = h[j][1];
          break;
        }
      }
    }
    cout << d << endl;
    cin >> n;
  }

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

#include <cstring>
#include <iostream>
#include <string>
using namespace std;
struct T {
  unsigned char a, b;
};
T array[1000000];
int main() {
  int n, m, i, j;
  unsigned char a, b;
  string ca, cb;
  bool flag;
  while (cin >> n && n) {
    flag = true;
    string out;
    memset(array, 0, sizeof(array));
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      array[i].a = a;
      array[i].b = b;
    }
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> a;
      ca = a;
      for (j = 0; j < n; j++) {
        cb = array[j].a;
        if (ca == cb) {
          flag = false;
          break;
        }
      }
      if (flag) {
        out += a;
      } else {
        out += array[j].b;
      }
      flag = true;
    }
    cout << out << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <string>
using namespace std;
struct T {
  unsigned char a, b;
};
T array[100000000];
int main() {
  int n, m, i, j;
  unsigned char a, b;
  string ca, cb;
  bool flag;
  while (cin >> n && n) {
    flag = true;
    string out;
    memset(array, 0, sizeof(array));
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      array[i].a = a;
      array[i].b = b;
    }
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> a;
      ca = a;
      for (j = 0; j < n; j++) {
        cb = array[j].a;
        if (ca == cb) {
          flag = false;
          break;
        }
      }
      if (flag) {
        out += a;
      } else {
        out += array[j].b;
      }
      flag = true;
    }
    cout << out << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  string data("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  string conv;
  char inp, inp2;
  string ans;
  int n, m;

  while (1) {
    ans = ("");
    conv = ("..............................................................");
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> inp >> inp2;
      conv[data.find(inp)] = inp2;
    }

    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> inp;
      if (conv[data.find(inp)] != '.')
        ans += conv[data.find(inp)];
      else
        ans += inp;
    }

    cout << ans << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {

  char conv[256];
  int n, n2;
  char inp1, inp2, inp3;
  char ans[100000001];

  for (int i = 0; i < 256; i++)
    conv[i] = '-';

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> inp1 >> inp2;
    conv[(int)inp1] = inp2;
  }

  cin >> n2;
  for (int i = 0; i < n2; i++) {
    cin >> inp3;
    if (conv[(int)inp3] == '-')
      ans[i] = inp3;
    else
      ans[i] = conv[(int)inp3];
  }

  cout << ans << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  do {
    char a[256], b[256];
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    int num;
    char s;
    cin >> num;
    for (int i = 0; i < num; i++) {
      cin >> s;
      for (int j = 0; j < n; j++) {
        if (s == a[j]) {
          s = b[j];
          break;
        }
      }
      cout << s;
    }
    cout << endl;
    cin >> n;
  } while (n != 0);
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  char s[256];
  cin >> n;
  do {
    char a[256], b[256];
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    int num;
    cin >> num;
    for (int i = 0; i < num; i++) {
      cin >> s[i];
      for (int j = 0; j < n; j++) {
        if (s[i] == a[j]) {
          s[i] = b[j];
          break;
        }
      }
    }
    s[num] = '\\0';
    cout << s << endl;
    cin >> n;
  } while (n != 0);
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
// #include<cstring>
#include <iostream>
#define N 1000

void ini(void);
using namespace std;
char before[N];
char after[N];
char sth /*[N]*/;
int main() {
  ini();
  int n;

  int i;
  while (cin >> n) {
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {

      cin >> before[i] >> after[i];
    }

    int m;

    cin >> m;

    for (i = 0; i < m; i++) {

      cin >> sth /*[i]*/;
      for (int j = 0; j < n; j++) {
        if (sth /*[i]*/ == before[j]) {
          sth /*[i]*/ = after[j];
          break;
        }
      }
      printf("%c", sth /*[i]*/);
    }
    cout << endl;
  }
  return 0;
}

void ini(void) {

  int i;

  for (i = 0; i < N; i++) {
    // sth[i]=-1;
    before[i] = -1;
    after[i] = -1;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
// #include<cstring>
#include <iostream>
#define N 100000

void ini(void);
using namespace std;
char before[N];
char after[N];
char sth /*[N]*/;
int main() {
  ini();
  int n;

  int i;
  while (cin >> n) {
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {

      cin >> before[i] >> after[i];
    }

    int m;

    cin >> m;

    for (i = 0; i < m; i++) {

      cin >> sth /*[i]*/;
      for (int j = 0; j < m; j++) {
        if (sth /*[i]*/ == before[j]) {
          sth /*[i]*/ = after[j];
          break;
        }
      }
      printf("%c", sth /*[i]*/);
    }
    cout << endl;
  }
  return 0;
}

void ini(void) {

  int i;

  for (i = 0; i < N; i++) {
    // sth[i]=-1;
    before[i] = -1;
    after[i] = -1;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  while (true) {
    map<char, char> dic;
    vector<char> data;
    cin >> n;
    if (n == 0)
      exit(0);
    while (n-- > 0) {
      char a, b;
      cin >> a >> b;
      dic[a] = b;
    }
    cin >> n;
    while (n-- > 0) {
      char a;

      cin >> a;
      auto buf = dic.find(a);
      if (buf == dic.end())
        cout << a;
      else
        cout << buf->second;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (true) {
    map<char, char> dic;
    vector<char> data;
    if (n == 0)
      exit(0);
    while (n-- > 0) {
      char a, b;
      cin >> a >> b;
      dic[a] = b;
    }
    cin >> n;
    while (n-- > 0) {
      char a;

      cin >> a;
      auto buf = dic.find(a);
      if (buf == dic.end())
        cout << a;
      else
        cout << buf->second;
    }
  }
  cout << endl;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, i;
  char c[75] = {};
  char d[75] = {};
  char a, b;
  for (int i = 0; i < 75; i++) {
    d[i] = '0' + i;
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < 75; i++) {
      c[i] = d[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      c[a - '0'] = b;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a;
      cout << c[a - '0'];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i;
  char c[62] = {};
  char a, b;
  char d = 's';
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < 62; i++) {
      c[i] = '0' + i;
    }
    for (int i = 0; i < n; i++) {
      cin >> a;
      cin >> b;
      c[a - '0'] = b;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a;
      cout << c[a - '0'];
    }
    cout << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int n, m, i;

  while (scanf("%d", &n), n) {

    char data[10000000], afch[200] = {0};
    bool bech[200] = {0};
    char temp, str[5];

    for (i = 0; i < n; i++) {
      scanf("%s", str);
      temp = str[0];
      bech[temp - 48] = 1;
      scanf("%s", str);
      afch[temp - 48] = str[0];
    }

    scanf("%d", &m);

    for (i = 0; i < m; i++) {
      scanf("%s", str);
      data[i] = str[0];
    }
    for (i = 0; i < m; i++) {
      if (bech[data[i] - 48] == 1)
        printf("%c", afch[data[i] - 48]);
      else
        printf("%c", data[i]);
    }
    puts("");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, m, i, j;
  char str[10000005];
  char temp, temp2[2];
  while (scanf("%d", &n), n) {
    bool change[70] = {0};
    char afch[70] = {0};
    temp = getchar();

    for (i = 0; i < n; i++) {
      scanf("%c %c", &temp2[0], &temp2[1]);
      temp = getchar();

      change[temp2[0] - 48] = 1;
      afch[temp2[0] - 48] = temp2[1];
    }
    scanf("%d", &m);
    temp = getchar();
    for (i = 0; i < m; i++) {
      scanf("%c", &str[i]);
      temp = getchar();
      if (change[str[i] - 48] == 1)
        str[i] = afch[str[i] - 48];
    }
    for (i = 0; i < m; i++) {
      printf("%c", str[i]);
    }
    puts("");
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
char a[1000][2];
char b[100000];
int c, d;
int main() {
  while (1) {
    cin >> c;
    if (c == 0)
      return 0;
    for (int i = 0; i < c; i++) {
      cin >> a[i][0] >> a[i][1];
    }
    cin >> d;
    for (int i = 0; i < d; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < d; i++) {
      for (int j = 0; j < c; j++) {
        if (b[i] == a[j][0]) {
          // cout << "max" << endl;
          b[i] = a[j][1];
          break;
        }
      }
    }
    for (int i = 0; i < d; i++) {
      cout << b[i];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
char str[1000000][2];
char str2[100000] = {NULL};
int main() {
  int ruio, hideo;
  while (1) {
    cin >> ruio;
    if (ruio == 0)
      return 0;
    for (int i = 0; i < ruio; i++) {
      cin >> str[i][0] >> str[i][1];
    }
    cin >> hideo;
    for (int i = 0; i < 10; i++) {
      cin >> str2[i];
      for (int j = 0; j < ruio; j++) {
        if (str2[i] == str[j][0]) {
          str2[i] = str[j][1];
          break;
        }
      }
    }
    cout << str2 << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  while (cin >> n && n) {
    char henkan[100000] = {};
    char henkango[100000] = {};
    for (int i = 0; i < n; i++) {
      cin >> henkan[i] >> henkango[i];
    }
    int m;
    cin >> m;
    char data[100000] = {};
    for (int i = 0; i < m; i++) {
      cin >> data[i];
      for (int j = 0; j < n; j++) {
        if (data[i] == henkan[j]) {
          data[i] = henkango[j];
          break;
        }
      }
    }
    cout << data << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    char henkan[10000] = {};
    char henkango[10000] = {};
    for (int i = 0; i < n; i++) {
      cin >> henkan[i] >> henkango[i];
    }
    int m;
    cin >> m;
    char data[10000] = {};
    for (int i = 0; i < m; i++) {
      cin >> data[i];
      for (int j = 0; j < n; j++) {
        if (data[i] == henkan[j]) {
          data[i] = henkango[j];
        }
      }
    }
    for (int i = 0; i < m; i++) {
      cout << data[i];
    }
    cout << endl;
  }

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

#include <cstdio>
#include <iostream>
using namespace std;
char in[100000000];
int main(void) {
  int n;
  unsigned long long m;
  char bfr[200], aft[200];
  int flag = 0;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> bfr[i] >> aft[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> in[i];
    }

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (in[i] == bfr[j] && flag == 0) {
          in[i] = aft[j];
          flag = 1;
        }
      }
      flag = 0;
    }

    for (int i = 0; i < m; i++) {
      cout << in[i];
    }
    cout << endl;
    for (int i = 0; i < 200; i++) {
      bfr[i] = 0;
      aft[i] = 0;
    }
  }
  return 0;
}

Error: 127
/tmp/1471fcea-61a2-4a9f-a16f-c5912b2751f0.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
char in[100000000];
int main(void) {
  int n;
  unsigned long long m;
  char bfr[20], aft[20];
  int flag = 0;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> bfr[i] >> aft[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> in[i];
    }

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (in[i] == bfr[j] && flag == 0) {
          in[i] = aft[j];
          flag = 1;
        }
      }
      flag = 0;
    }

    for (int i = 0; i < m; i++) {
      cout << in[i];
    }
    cout << endl;
    for (int i = 0; i < 20; i++) {
      bfr[i] = 0;
      aft[i] = 0;
    }
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

/**********************************************

1.data_convert.cpp
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:49

 **********************************************/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  int n = 0;

  while (1) {

    int n = 0;
    int k = 0;

    cin >> n;
    if (n == 0)
      break;
    vector<char> a(n);
    vector<char> b(n);

    for (int i = 0; i < n; i++) {

      cin >> a[i] >> b[i];
    }

    cin >> k;
    vector<char> data(k);

    for (int i = 0; i < k; i++) {

      cin >> data[i];
      for (int j = 0; j < n; j++) {

        if (data[i] == a[j]) {
          data[i] = b[j];
          break;
        }
      }
    }

    for (int i = 0; i < k; i++) {
      cout << data[i];
    }

    cout << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

/**********************************************

1.data_convert.cpp
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@09:38

 **********************************************/

#include <iostream>
using namespace std;
#define MAXSIZE 1000

int main(void) {

  int n = 0;
  int num = 0;
  char a[MAXSIZE], b[MAXSIZE];
  char data[1000000];

  while (1) {

    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {

      cin >> a[i] >> b[i];
      // cout << a[i] << ' ' << b[i] << endl;
    }

    cin >> num;

    for (int i = 0; i < num; i++) {

      cin >> data[i];
    }

    for (int j = 0; j < n; j++) {

      for (int i = 0; i < num; i++) {

        if (a[i] == data[j]) {
          data[j] = b[i];
        }
      }
    }

    for (int i = 0; i < num; i++) {
      cout << data[i];
    }

    cout << endl;
  }

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

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n;
  while (cin >> n) {

    string s = "";

    if (n == 0) {
      break;
    }
    map<char, char> m;
    char a, b;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      m[a] = b;
    }
    int d;
    cin >> d;
    for (int i = 0; i < d; i++) {
      cin >> a;
      if (m.count(a)) {
        a = m[a];
      }
      s += a;
    }
    cout << s << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, m;
  char a, b, l;
  while (cin >> n) {
    if (n == 0)
      break;
    char A[n + 1], B[n + 1], C[n + 1];
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      A[i] = a;
      B[i] = b;
    }
    cin >> m;
    for (int j = 0; j < m; j++) {
      cin >> l;
      C[j] = l;
      for (int o = 0; o < n; o++) {
        if (A[o] == l) {
          C[j] = B[o];
        }
      }
    }
    for (int k = 0; k < m; k++) {
      cout << C[k];
    }
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  while (1) {
    int a, b;
    char aa[100], bb[100], d, dd[10000000];
    scanf("%d", &a);
    if (a == 0)
      break;
    for (int i = 0; i < a; i++)
      scanf(" %c %c", &aa[i], &bb[i]);
    scanf("%d", &b);
    for (int i = 0; i < b; i++) {
      scanf(" %c", &dd[i]);
      for (int j = 0; j < a; j++) {
        if (dd[i] == aa[j]) {
          printf("%c", bb[j]);
          break;
        }
        if (j == (a - 1))
          printf("%c", dd[i]);
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  while (1) {
    int a, b;
    char aa[100], bb[100], d, dd[100000000];
    scanf("%d", &a);
    if (a == 0)
      break;
    for (int i = 0; i < a; i++)
      scanf(" %c %c", &aa[i], &bb[i]);
    scanf("%d", &b);
    for (int i = 0; i < b; i++) {
      scanf(" %c", &dd[i]);
      for (int j = 0; j < a; j++) {
        if (dd[i] == aa[j]) {
          dd[i] = bb[j];
          break;
        }
      }
      printf("%c", dd[i]);
    }
    printf("\\n");
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int n, m;
  char a[1000], b[1000], c;
  int i, j;

  scanf("%d", &n);
  while (n != 0) {
    for (i = 0; i < n; i++) {
      scanf(" %c %c", &a[i], &b[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf(" %c", &c);
      for (j = 0; j < n; j++) {
        if (c == a[j]) {
          c = b[j];
          break;
        }
      }
      printf("%c", c);
    }
    printf("\\n");
    scanf("%d", &n);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, m;
  char a[1000], b[1000], c[10000];
  int i, j;

  scanf("%d", &n);
  while (n != 0) {
    for (i = 0; i < n; i++) {
      scanf(" %c %c", &a[i], &b[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf(" %c", &c[i]);
      for (j = 0; j < n; j++) {
        if (c[i] == a[j]) {
          c[i] = b[j];
          break;
        }
      }
    }
    for (i = 0; i < m; i++) {
      printf("%c", c[i]);
    }
    printf("\\n");
    scanf("%d", &n);
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int ha[200];

  while (1) {
    rep(i, 200) ha[i] = 0;

    int n, m;
    scanf("%d", &n);
    if (n == 0)
      break;

    char a, b;
    rep(i, n) {
      cin >> a >> b;
      ha[a] = b;
    }

    scanf("%d", &m);

    vector<char> str;

    rep(i, m) {
      cin >> a;
      if (ha[a] != 0) {
        a = ha[a];
      }
      str.push_back(a);
    }

    rep(i, str.size()) printf("%c", str[i]);
    puts("");
  }
}
/*
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
*/

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  while (1) {
    int n, m;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    char code[1000];
    char hyou[1000];
    for (int i = 0; i < n; i++) {
      scanf("%c%c", &code[i], &hyou[i]);
    }
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      char a;
      scanf("%c", &a);
      for (int i = 0; i < n; i++) {
        if (a == code[i]) {
          a = hyou[i];
          break;
        }
      }
      printf("%c", a);
    }
    puts("");
  }
}