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

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

using namespace std;

int main(int argc, char const *argv[]) {
  int table_count = 0;
  char key, value;

  while (1) {
    /* ---  読み込み --- */
    cin >> table_count;
    if (table_count == 0) {
      return 0;
    };
    //
    // cout << "table_count" << table_count << endl;

    map<char, char> map;
    for (int i = 0; i < table_count; i++) {
      // cout << i << ": ";
      cin >> key;
      cin >> value;
      map[key] = value;
      //
      // cout << key << " " << value << endl;
    }

    /* ---  出力 --- */
    int char_count;
    cin >> char_count;
    // scanf("%d\\n", &char_count);
    //
    // cout << "char_count :" << char_count << endl;
    for (int i = 0; i < char_count; i++) {
      //
      // cout << i << " :";
      char tmp_char;
      cin >> tmp_char;

      if (map.find(tmp_char) == map.end()) {
        cout << tmp_char;
      } else {
        cout << map[tmp_char];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int max(int a, int b);
int min(int a, int b);
int is_prime(int n);

int main(int argc, char const *argv[]) {
  int n;
  while (cin >> n, n) {
    // if ( n==-1 && p==-1 ) { break; }
    vector<int> arr(5);
    vector<int> sum(n);
    int min_num = 0;
    int max_num = 0;
    for (int t = 0; t < n; t++) {
      for (int i = 0; i < 5; i++) {
        cin >> arr[i];
        sum[t] += arr[i];
      }
    }
    sort(sum.begin(), sum.end());
    min_num = sum[0];
    max_num = sum[n - 1];
    cout << max_num << " " << min_num << endl;
  }
  return 0;
}

int is_prime(int n) {
  if (n == 1 || n == 0) {
    return 0;
  }
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}

int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int min(int a, int b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  for (int u = 0; u < 5; u++) {
    long long n, m;
    char a[1000], b[1000], p[100000];

    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (long i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    cin >> m;
    for (long long j = 0; j < m; j++) {
      cin >> p[j];
    }

    for (long long j = 0; j < m; j++) {
      for (long i = 0; i < n; i++) {
        if (p[j] == a[i]) {
          p[j] = b[i];
          break;
        }
      }
    }

    for (int j = 0; j < m; j++) {
      cout << p[j];
    }
    cout << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  for (int k = 0; k < 5; k++) {
    long n, m;

    char a[10000], b[10000], x[10000];

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

    for (long i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> m;

    for (long j = 0; j < m; j++) {
      cin >> x[j];
    }

    for (long j = 0; j < m; j++) {
      for (long i = 0; i < n; i++) {
        if (a[i] == x[j]) {
          x[j] = b[i];
        }
      }
    }

    for (long j = 0; j < m; j++) {
      cout << x[j];
      if (j == m - 1) {
        cout << endl;
      }
    }
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<vector<char>> c(n, vector<char>(2));
    const int first = 0;
    const int second = 1;
    while (n--) {
      cin >> c[n][first] >> c[n][second];
    }
    cin >> n;
    char in;
    string ans;
    while (n--) {
      cin >> in;
      for (int i = 0; i < c.size(); i++) {
        if (in == c[i][first]) {
          in = c[i][second];
          break;
        }
      }
      ans += in;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n;
  while (cin >> n) {
    vector<vector<char>> c(n, vector<char>(2));
    const int first = 0;
    const int second = 1;
    while (n--) {
      cin >> c[n][first] >> c[n][second];
    }
    cin >> n;
    char in;
    string ans;
    while (n--) {
      cin >> in;
      for (int i = 0; i < c.size(); i++) {
        if (in == c[i][first]) {
          in = c[i][second];
          break;
        }
      }
      ans += in;
    }
    cout << ans << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, i, j;
  while (1) {
    cin >> a;
    if (a == 0)
      break;
    vector<char> from(a);
    vector<char> to(a);
    for (i = 0; i < a; i++) {
      cin >> from[i] >> to[i];
    }
    cin >> b;
    vector<char> v(b);
    for (i = 0; i < b; i++) {
      cin >> v[i];
      for (j = 0; j < a; j++) {
        if (v[i] == from[j]) {
          v[i] = to[j];
          break;
        }
      }
    }
    for (i = 0; i < b; i++) {
      cout << v[i];
    }
    cout << "\\n";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int na, nb;
  int i, k;
  int kai = 0;
  char a[99], b[99];
  char s[99][99];
  while (1) {
    cin >> na;
    if (na == 0)
      break;
    for (i = 0; i < na; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> nb;
    for (i = 0; i < nb; i++) {
      cin >> s[kai][i];
      for (k = 0; k < na; k++) {
        if (s[kai][i] == a[k]) {
          s[kai][i] = b[k];
          break;
        }
      }
    }
    kai++;
  }
  for (i = 0; i <= kai; i++) {
    for (k = 0; k < nb; k++) {
      cout << s[i][k] << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  string dic[100000];
  string words[100000];
  map<string, string> mp;
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    string result = "";
    for (int i = 0; i < n; i++) {
      cin >> dic[i];
      cin >> mp[dic[i]];
    }
    cin >> m;
    for (int k = 0; k < m; k++) {
      cin >> words[k];
      for (int j = 0; j < n; j++) {
        if (words[k] == dic[j]) {
          words[k] = mp[dic[j]];
          break;
        }
      }
      result = result + words[k];
    }
    cout << result << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  string dic[100];
  string words[100];
  map<string, string> mp;
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    string result = "";
    for (int i = 0; i < n; i++) {
      cin >> dic[i];
      cin >> mp[dic[i]];
    }
    cin >> m;
    for (int k = 0; k < m; k++) {
      cin >> words[k];
      for (int j = 0; j < n; j++) {
        if (words[k] == dic[j]) {
          words[k] = mp[dic[j]];
          break;
        }
      }
      result = result + words[k];
    }
    cout << result << "\\n";
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char c, ch1, ch2;
  int i, j, n, m;
  string str;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vector<pair<char, char>> change;
    for (i = 0; i < n; i++) {
      cin >> ch1 >> ch2;
      change.push_back(pair<char, char>(ch1, ch2));
    }
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> c;
      for (j = 0; j < change.size(); j++) {
        if (change[j].first == c) {
          c = change[j].second;
          break;
        }
      }
      cout << c;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  char c, ch1, ch2;
  int i, j, n, m;
  string str;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vector<pair<char, char>> change;
    for (i = 0; i < n; i++) {
      cin >> ch1 >> ch2;
      change.push_back(pair<char, char>(ch1, ch2));
    }
    char str[10000];
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> c;
      for (j = 0; j < change.size(); j++) {
        if (change[j].first == c) {
          c = change[j].second;
          break;
        }
      }
      str[i] = c;
    }
    str[i] = '\\0';
    cout << str << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  while (1) {
    int m, n;
    char cha[100000], con[100000], a[100000];
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> cha[i] >> con[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      for (int j = 0; j < m; j++) {
        if (a[i] == cha[j]) {
          a[i] = con[j];
          break;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
    cout << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  while (1) {
    int m, n;
    char cha[10000], con[10000], a[10000];
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> cha[i] >> con[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      for (int j = 0; j < m; j++) {
        if (a[i] == cha[j]) {
          a[i] = con[j];
          break;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
    cout << "\\n";
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  int m;
  char data;

  bool flg = false;
  while (1) {
    cin >> n;
    char a[n + 1], b[n + 1];
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> data;
      flg = false;
      for (int j = 0; j < n; j++) {
        if (data == a[j] && !flg) {
          data = b[j];
          flg = true;
        }
      }
      cout << data;
    }
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  int m;
  char data;
  char a[11], b[11];
  bool flg = false;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> data;
      flg = false;
      for (int j = 0; j < n; j++) {
        if (data == a[j] && !flg) {
          data = b[j];
          flg = true;
        }
      }
      cout << data;
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int n, m, co[1000] = {0}, i, j;
  char a[1000] = {0}, b[1000] = {0}, c[100011] = {0};
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      co[i] = 1;
    }
    cin >> m;
    for (j = 0; j < m; j++) {
      cin >> c[j];
      for (i = 0; i < n; i++) {
        if (c[j] == a[i]) {
          c[j] = b[i];
          co[i] = 0;
          break;
        }
      }
    }
    for (j = 0; j < m; j++) {
      cout << c[j];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, co[100] = {0}, i, j;
  char a[100] = {0}, b[100] = {0}, c[100] = {0};
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      co[i] = 1;
    }
    cin >> m;
    for (j = 0; j < m; j++) {
      cin >> c[j];
      for (i = 0; i < n; i++) {
        if (c[j] == a[i]) {
          c[j] = b[i];
          co[i] = 0;
          break;
        }
      }
    }
    for (j = 0; j < m; j++) {
      cout << c[j];
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a, i, n) for (int i = a; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define debug(x) cout << x << endl
#define s_1(x) cin >> x
#define s_2(x, y) cin >> x >> y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////

int main() {
  int N, len;
  char str[10000][10] = {};
  char s[100000] = {};

  while (1) {
    s_1(N);
    if (N == 0)
      break;
    rep(i, N) cin >> str[i][0] >> str[i][1];
    s_1(len);

    rep(i, len) {
      s_1(s[i]);
      rep(j, N) {
        if (str[j][0] == s[i]) {
          s[i] = str[j][1];
          break;
        }
      }
    }
    rep(i, len) cout << s[i];
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a, i, n) for (int i = a; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define debug(x) cout << x << endl
#define s_1(x) cin >> x
#define s_2(x, y) cin >> x >> y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////

int main() {
  int N, len;
  char str[10000][10] = {};
  char s[10000] = {};

  while (1) {
    s_1(N);
    if (N == 0)
      break;
    rep(i, N) cin >> str[i][0] >> str[i][1];
    s_1(len);

    rep(i, len) {
      s_1(s[i]);
      rep(j, N) {
        if (str[j][0] == s[i]) {
          s[i] = str[j][1];
          break;
        }
      }
    }
    rep(i, len) cout << s[i];
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  char c;
  vector<char> transB, transA;
  vector<char> input;
  while (cin >> n) {
    if (n == 0)
      return 0;

    transB.clear();
    transA.clear();
    input.clear();
    for (int i = 0; i < n; i++) {
      cin >> c;
      transB.push_back(c);
      cin >> c;
      transA.push_back(c);
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> c;
      input.push_back(c);
    }
    for (int i = 0; i < m; i++) {
      for (int k = 0; k < n; k++) {
        if (input[i] == transB[k]) {
          input[i] = transA[k];
          break;
        }
      }
    }

    for (int i = 0; i < m; i++) {
      cout << input[i];
    }
    cout << endl;
  }
}


Error: -11

Fixed submission:

#include <iostream>
#define N 100000000
using namespace std;
struct Trans {
  char before, after;
};

int main() {
  int n, m;
  Trans trans[N];
  char input[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> trans[i].before >> trans[i].after;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> input[i];
  }

  for (int i = 0; i < m; i++) {
    for (int k = 0; k < n; k++) {
      if (input[i] == trans[k].before) {
        input[i] = trans[k].after;
        break;
      }
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  int i, j, n, x, l;
  char a[100001], b[100001], c[100001], m;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> x;
    for (j = 0; j < x; j++) {
      cin >> c[j];
    }
    for (l = 0; l < x; l++) {
      for (int k = 0; k < n; ++k) {
        if (c[l] == a[k]) {
          c[l] = b[k];
          break;
        }
      }
    }
    for (int k = 0; k < x; ++k) {
      cout << c[k];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i, j, n, x, l;
  char a[10000], b[10000], c[10000], m;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cin >> x;
    for (j = 0; j < x; j++) {
      cin >> c[j];
    }
    for (l = 0; l < x; l++) {
      for (int k = 0; k < n; ++k) {
        if (c[l] == a[k]) {
          c[l] = b[k];
          break;
        }
      }
    }
    for (int k = 0; k < x; ++k) {
      cout << c[k];
    }
    cout << endl;
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int n, i, j, m, f;
  char a[256], b[256], x;
  while (1) {
    scanf("%d ", &n);
    if (n == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      scanf("%c %c ", &a[i], &b[i]);
    }

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

Error: -11

Fixed submission:

#include <stdio.h>
int main() {
  int n, i, j, m, f;
  char a[256], b[256], x;
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      scanf("%s %s", &a[i], &b[i]);
    }

    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%s", &x);
      f = 0;
      for (j = 0; j < n; j++) {
        if (x == a[j]) {
          printf("%s", b[j]);
          f = 1;
          break;
        }
      }
      if (f == 0) {
        printf("%s", x);
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

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

int main(int argc, char const *argv[]) {
  int i, n, m;
  char dest, target;

  while (true) {
    cin >> n;
    map<char, char> table;

    if (n == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      cin >> dest;
      cin >> target;
      table[dest] = target;
    }

    cin >> m;

    for (i = 0; i < m; i++) {
      cin >> target;

      if (table.find(target) != table.end()) {
        cout << table[target];
      } else {
        cout << target;
      }
    }
    cout << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
int main() {
  int i = 0;
  std::cin >> i;
  std::vector<char> before, after, input;
  for (int j = 0; j < i; ++j) {
    std::cin >> before[j] >> after[j];
  }
  int o = 0;
  std::cin >> o;
  for (int j = 0; j < o; ++j) {
    std::cin >> input[j];
  }
  for (int j = 0; j < 0; ++j) {
    if (input[j] == before[j]) {
      input[j] = after[j];
    }
  }
  for (int j = 0; j < o - 1; ++j) {
    std::cout << input[j];
  }
  std::cout << input[o - 1] << std::endl;
  return 0;
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;

  int c;
  string d;
  int m;
  int e;
  int f;
  while (cin >> n) {
    if (n != 0) {
      string a[n];
      string b[n];
      c = 0;
      while (c < n) {
        cin >> a[c];
        cin >> b[c];
        c = c + 1;
      }

      cin >> m;
      c = 0;

      while (c < m) {
        cin >> d;
        e = 0;
        f = 0;
        while (e < n) {
          if (d == a[e]) {
            cout << b[e];
            f = 1;
          }
          e = e + 1;
        }
        if (f == 0) {
          cout << d;
        }
        c = c + 1;
      }
      cout << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string a[n];
  string b[n];

  int c;
  string d;
  int m;
  int e;
  int f;
  while (cin >> n) {
    if (n != 0) {
      c = 0;
      while (c < n) {
        cin >> a[c];
        cin >> b[c];
        c = c + 1;
      }

      cin >> m;
      c = 0;

      while (c < m) {
        cin >> d;
        e = 0;
        f = 0;
        while (e < n) {
          if (d == a[e]) {
            cout << b[e];
            f = 1;
          }
          e = e + 1;
        }
        if (f == 0) {
          cout << d;
        }
        c = c + 1;
      }
    }
  }
}
Problem p00424 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  for (;;) {
    char henkan[100000][2];
    char str[100000];
    int n, m;
    char temp;
    bool flg = 0;

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

    for (int i = 0; i < n; i++) {
      cin >> henkan[i][0] >> henkan[i][1];
    }
    /*
    for(int i = 0; i < n; i++){
            cout << henkan[i][1] << endl;
    }
    */

    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> str[i];
    }

    for (int i = 0; i < m; i++) {
      flg = 0;
      for (int j = 0; j < n; j++) {
        if (str[i] == henkan[j][0]) {
          temp = henkan[j][1];
          flg = 1;
        }
      }
      if (flg == 1) {
        printf("%c", temp);
      } else {
        printf("%c", str[i]);
      }
    }
    cout << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  for (;;) {
    char henkan[1000][2];
    char str[1000];
    int n, m;
    char temp;
    bool flg = 0;

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

    for (int i = 0; i < n; i++) {
      cin >> henkan[i][0] >> henkan[i][1];
    }
    /*
    for(int i = 0; i < n; i++){
            cout << henkan[i][1] << endl;
    }
    */

    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> str[i];
    }

    for (int i = 0; i < m; i++) {
      flg = 0;
      for (int j = 0; j < n; j++) {
        if (str[i] == henkan[j][0]) {
          temp = henkan[j][1];
          flg = 1;
        }
      }
      if (flg == 1) {
        printf("%c", temp);
      } else {
        printf("%c", str[i]);
      }
    }
    cout << endl;
  }
}
Problem p00424 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int n, m;
    char secret;
    char A[100] = {0}, B[100] = {0};
    cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      cin >> A[i] >> B[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> secret;
      int flag = 0;
      for (int j = 0; j < n; j++) {
        if (secret == A[j]) {
          printf("%c", B[j]);
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        printf("%c", secret);
    }
    printf("\\n");
  }
}

Error: TLE

Fixed submission:

#include <cstdio>

int n, m;

int main() {
  while (1) {
    char A[128] = {0}, B[128] = {0};
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      scanf("%c %c", A[i], B[i]);
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      int flag = 0;
      char secret;
      scanf("%c", &secret);
      for (int j = 0; j < n; j++) {
        if (secret == A[j]) {
          printf("%c\\n", B[j]);
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        printf("%c\\n", secret);
    }
  }
  return 0;
}