Problem:
与えられた変換表にもとづき，データを変換するプログラムを作成しなさい．
データに使われている文字は英字か数字で，英字は大文字と小文字を区別する．変換表に現れる文字の順序に規則性はない．
変換表は空白をはさんで前と後ろの 2 つの文字がある(文字列ではない)．変換方法は，変換表のある行の前の文字がデータに現れたら，そのたびにその文字を後ろの文字に変換し出力する．変換は 1 度だけで，変換した文字がまた変換対象の文字になっても変換しない．変換表に現れない文字は変換せず，そのまま出力する．
入力ファイルには，変換表（最初の n + 1 行）に続き変換するデータ（n + 2 行目以降）が書いてある． 1 行目に変換表の行数 n，続く n 行の各行は，空白をはさんで 2 つの文字，さらに続けて， n + 2 行目に変換するデータの行数 m，続く m 行の各行は 1 文字である． m ≤ 10
5
とする．出力は，出力例のように途中に空白や改行は入れず 1 行とせよ．
入力例
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
出力例
aBC5144aba
入力
入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．
出力
データセットごとに、変換後の文字列を１行に出力する．
入力例
3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
0
出力例
aBC5144aba
aBC5144aba
各データセットの出力（変換後の文字列）の後に改行を入れること．
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

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

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        map<char, char> mp;
        for (int i = 0; i < n; i++) {
            char a, b;
            cin >> a >> b;
            mp[a] = b;
        }

        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            char c;
            cin >> c;
            if (mp.find(c) == mp.end())
                cout << c;
            else
                cout << mp[c];
        }
        cout << "\n";
    }
}
accuracy: 1
time_ms: 90
memory_kb: 2920
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<n; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define yesno(ok) puts(ok ? "Yes" : "No") 
using ll = long long;
using P = pair<int,int>;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		map<char, char> mp;
		rep(i,n) {
			char x, y;
			cin >> x >> y;
			mp[x] = y;
		}
		int t;
		cin >> t;
		rep(ti,t) {
			char a;
			cin >> a;
			if (mp.count(a)) cout << mp[a];
			else cout << a;
		}
		cout << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3060
final_rank: 7

code_snippet: #include <iostream>

int main() {
  int n;

  while(std::cin >> n && n) {
    int d[256] = {};
    char a, b;
    while (--n >= 0) {
      std::cin >> a >> b;
      d[a] = b - a;
    }
    std::cin >> n;
    while (--n >= 0) {
      std::cin >> a;
      std::cout << static_cast<char>(a + d[a]);
    }
    std::cout << "\n";
  }
}
accuracy: 1
time_ms: 100
memory_kb: 3076
final_rank: 11

code_snippet: #include <iostream>

int main() {
  int n;
  for (char a, b; std::cin >> n, n; std::cout << '\n') {
    int d[256] = {};
    for (; n--; d[a] = b - a)
      std::cin >> a >> b;
    for (std::cin >> n; n--; std::cout << char(a + d[a]))
      std::cin >> a;
  }
}
accuracy: 1
time_ms: 90
memory_kb: 2900
final_rank: 1

code_snippet: #include <stdio.h>
#include <iostream>

int main() {
  int n;
  char a, b;
  int d[256];

  while (std::cin >> n && n) {
    std::fill(d, d + 256, 0);
    for (; n--; d[a] = b - a)
      std::cin >> a >> b;
    for (std::cin >> n; n--; std::cout << char(a + d[a]))
      std::cin >> a;
    std::cout << "\n";
  }
}
accuracy: 1
time_ms: 90
memory_kb: 2900
final_rank: 1

code_snippet: #include <iostream>

int main() {
  char a, b;
  int n;
  while (std::cin >> n && n) {
    int d[256] = {};
    for (; n--; d[a] = b - a)
      std::cin >> a >> b;
    std::cin >> n;
    for (; n--; std::cout << static_cast<char>(a + d[a]))
      std::cin >> a;
    std::cout << std::endl;
  }
}
accuracy: 1
time_ms: 90
memory_kb: 2980
final_rank: 5

code_snippet: #include <iostream>
#include <cstring>

int main() {
  int n;
  int d[256];
  char a, b;
  
  while(std::cin >> n && n) {
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n; ++i) {
      std::cin >> a >> b;
      d[a] = b - a;
    }
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
      std::cin >> a;
      std::cout << char(a + d[a]);
    }
    std::cout << "\n";
  }
}
accuracy: 1
time_ms: 90
memory_kb: 2900
final_rank: 1

code_snippet: #include <iostream>
#include <cstring>
#define z std::cin >>
int main() {
    int n;
    for (char a, b; z n, n; puts("")) {
        int d[256] = {};
        for (; n--; d[a] = b - a)
            z a >> b;
        for (z n; n--; putchar(a + d[a]))
            z a;
        memset(d, 0, sizeof(d));    // reset array for next iteration
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3336
final_rank: 14

code_snippet: #include <iostream>
#include <cstring>
#define z std::cin >>
int main() {
  int n;
  for (char a, b; z n, n; puts("")) {
    int d[256] = {};
    for (; n--; d[a] = b - a)
      z a >> b;
    for (z n; n--; putchar(a + d[a]))
      z a;
    memset(d, 0, sizeof(d)); // Adding this line to clear the array after each test case
  }
}
accuracy: 1
time_ms: 70
memory_kb: 3368
final_rank: 17

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

int main(){
    while(1){
        int n;
        cin >>n;
        if(n==0){
            break;
        }
        vector<pair<char,char>> code(n);
        for(int i=0;i<n;i++){
            cin >> code.at(i).first >> code.at(i).second;
        }
        int m;
        cin >> m;
        for(int i=0;i<m;i++){
            char c;
            cin >> c;
            for(int j=0;j<n;j++){
                if(c == code.at(j).first){
                    c = code.at(j).second;
                    break;
                }
            }
            cout << c;
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3344
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	while (n != 0) {
		map<char, char> code;
		for (int i = 0; i < n; i++) {
			char from, to;
			cin >> from >> to;
			code[from] = to;
		}
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			char in;
			cin >> in;
			auto it = code.find(in);
			if (it != code.end()) {
				cout << it->second;
			} else {
				cout << in;
			}
		}
		cout << endl;
		cin >> n;
	}
}
accuracy: 1
time_ms: 70
memory_kb: 3336
final_rank: 14

code_snippet: #include<iostream>
using namespace std;
char map[128];
int main(){
	int n,m;
	char a,b,c;
	while(cin>>n,n){
		for(int i=0;i<128;i++)
			map[i]=i;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			map[a]=b;
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>c;
			cout<<map[c];
		}
		cout<<endl;
	}
}
accuracy: 1
time_ms: 70
memory_kb: 3424
final_rank: 19

code_snippet: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>


#define MAX_LEN 100000

struct Node
{
	int a;
	int b;
	Node* parent;
	Node* left;
	Node* right;
};

Node* root;


void insertTree(Node key)
{
	Node* x = root;
	Node* y = 0;
	Node* z = new Node;
	z->left = z->right = 0;
	z->a = key.a;
	z->b = key.b;

	while (x)
	{
		y = x;
		if (z->a < x->a)
			x = x->left;
		else
			x = x->right;
	}

	z->parent = x;
	if (y == 0)
		root = z;
	else if (z->a < y->a)
		y->left = z;
	else
		y->right = z;
}

void freeTree(Node* x)
{
	if (x == 0)
		return;
	freeTree(x->left);
	freeTree(x->right);
	delete(x);
	x = 0;
}

char findTree(int a)
{
	char b;
	Node* x = root;
	while (x && x->a != a)
	{
		if (a < x->a)
			x = x->left;
		else
			x = x->right;
	}
	if (x)
		return x->b;

	return -1;
}


int main()
{
	int n, m;
	char a, b;
	Node tmp;
	while (1)
	{
		std::cin >> n;
		if (n == 0)
			break;


		for (int i = 0; i < n; i++)
		{
			std::cin >> a >> b;
			tmp.a = a;
			tmp.b = b;
			insertTree(tmp);
		}
		std::cin >> m;
		for (int i = 0; i < m; i++)
		{
			std::cin >> a;
			b = findTree(a);
			if (b == -1)
				std::cout << a;
			else
				std::cout << b;
		}
		std::cout << std::endl;
		freeTree(root);
		root = 0;
	}
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3076
final_rank: 9

code_snippet: //#include <atcoder/all>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll,ll>>>;
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;

void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	if (n < k) return 0;
	return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
int main() {
    while(1){
	ll N;
	cin >> N;
	if(N==0)return 0;
	map<char, char> M;
	rep(i, N) {
		char C, D;
		cin >> C >> D;
		M[C] = D;
	}
	ll a;
	cin >> a;
	string S="";
	rep(m,a) {
		char B;
		cin >> B;
		if (M.count(B)) {
			S = S + M[B];
		}
		else {
			S = S + B;
		}
	}
	cout << S << endl;}
}
accuracy: 1
time_ms: 410
memory_kb: 3332
final_rank: 20

code_snippet: #include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
using namespace std;

int main(){
	int N;
	cin >> N;
	while(N != 0){
		vector<vector<string> > howtoconvert;
		for(int i = 0; i < N; i++){
			vector<string> converttable;
			for(int i = 0; i < 2; i++){
				string s;
				cin >> s;
				converttable.push_back(s);
			}
			howtoconvert.push_back(converttable);
		}
		
		int M;
		cin >> M;
		for(int i = 0; i < M; i++){
			string now;
			cin >> now;
			for(int j = 0; j < N; j++){
				if(howtoconvert[j][0] == now){
					now = howtoconvert[j][1];
					break;
				}
			}
			cout << now;
		}
		cout << endl;
		cin >> N;
	}
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3384
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <map>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define logn long
#define lnog long
#define lgon long
#define itn int
typedef pair<long long, long long> P;
const long long INF = 1000000000000006;
int main() {
    long long N = 1; cin >> N;
    while (N != 0) {
        vector<pair<char, char> >A(N);
        map<char, char>MAP;
        for (long long i = 0; i < N; i++) {
            cin >> A[i].first >> A[i].second;
            MAP[A[i].first] = A[i].second;
        }
        long long M; cin >> M;
        for (long long i = 0; i < M; i++) {
            char ch; cin >> ch;
            for (long long j = 0; j < N; j++) {
                if (ch == A[j].first) {
                    ch = A[j].second;
                    break;
                }
            }
            cout << ch;
        }
        cout << endl;
        cin >> N;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 3064
final_rank: 8

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX/5
#define MOD 1000000007
#define pi 3.14159265358979
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl
//#define lint long long int

void vout(vector<int>A) {
	rep(i, A.size()) {
		cout << A[i];
		if (i == A.size() - 1) {
			cout << endl;
		}
		else {
			cout << ' ';
		}
	}
}

void vvout(vector<vector<int>>A) {
	rep(i, A.size()) {
		rep(j, A[i].size()) {
			cout << A[i][j];
			if (j == A[i].size() - 1) {
				cout << endl;
			}
			else {
				cout << ' ';
			}
		}
	}
}

signed main() {
	int N, M;
	while (1) {
		cin >> N;
		if (N == 0) {
			return 0;
		}
		else {
			map<char, char>A;
			char a, b;
			rep(i, N) {
				cin >> a >> b;
				A[a] = b;
			}
			cin >> M;
			char s;
			rep(i, M) {
				cin >> s;
				if (A.count(s) == 0) {
					cout << s;
				}
				else {
					cout << A[s];
				}
			}
			cout << endl;
		}
	}
}
accuracy: 1
time_ms: 100
memory_kb: 3092
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int N, M;
    char l, r;
    map<char, char> pa;
    string S;

    while(1) {
        cin >> N;
        if(N < 1) break;
        pa.clear();
        S.clear();
        rep(i, N) {
            cin >> l >> r;
            pa[l] = r;
        }
        cin >> M;
        rep(i, M) {
            cin >> l;
            S.push_back((pa.find(l) == pa.end()) ? l : pa.find(l)->second);
        }
        cout << S << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3292
final_rank: 13

code_snippet: #include<iostream>
#include<map>
#include<utility>
using namespace std;
int main(){
  int n,m;
  char x,y;
  while(true){
    map<char,char> ma;
    cin >> n;
    if(n == 0)
      break;
    for(int i = 0 ; i < n ; i++){
      cin >> x;
      cin >> y;
      ma[x] = y;
    }
    cin >> m;
    char str[m];
    for(int i = 0 ; i < m ; i++){
      cin >> str[i];
      if(ma.find(str[i]) != ma.end())
        str[i] = ma[str[i]];
    }
    for(int i = 0 ; i < m ; i++)
      cout << str[i];
    cout << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3100
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for (int i =0; i < (n); ++i)
using namespace std;

int main() {
        int N, M;
        char B, A, c;
        cin >> N;
        while (N != 0) {
                map<char, char> hen;
                rep(n, N) {
                        cin >> B >> A;
                        hen[B] = A;
                }
                cin >> M;
                rep(m, M) {
                        cin >> c;
                        if (hen.count(c)) {
                                cout << hen.at(c);
                        } else {
                                cout << c;
                        }
                }
                cout << endl;
                cin >> N;
        }

        return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3084
final_rank: 10