hiho Week 13 register

Ended

Participants:460

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-04 15:51:32

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    std::string str[210], s1, s2;
    int father[210] = {}, flag[210];
    int m, n, cnt = 1;
    int i, j, k;
    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> s1 >> s2;
        for(j = 1; j < cnt && str[j] != s1; j++);
        if(j == cnt)
            str[cnt++] = s1;
        for(k = 1; k < cnt && str[k] != s2; k++);
        if(k == cnt)
            str[cnt++] = s2;
        father[k] = j;
    }
    cin >> m;
    for(i = 0; i < m; i++) {
        cin >> s1 >> s2;
        if(s1 == s2) {
            cout << s1 << endl;
            continue;
        }
        memset(flag, 0, sizeof(flag));
        for(j = 1; j < cnt && str[j] != s1; j++);
        while(j) {
            flag[j] = 1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX