text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int max_n = 2e5 + 5; string a, b; int n; int main() { cin >> a >> b >> n; cout << a << " " << b << endl; while (n--) { string x, y; cin >> x >> y; if (a == x) a = y; if (b == x) b = y; cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, c, d; char A[15], B[15], C[15], D[15]; int n; long long zzz(char q[]) { long long tam = 0; for (int i = strlen(q) - 1; i >= 0; i--) tam = tam * 30 + q[i] - 'a' + 1; return tam; } void xxx(long long w) { while (w > 0) { int tam = w % 30; w /= 30; cout << char(tam + 'a' - 1); } } int main() { cin >> A >> B; a = zzz(A); b = zzz(B); xxx(a); cout << ' '; xxx(b); cout << endl; cin >> n; for (int i = 0; i < n; i++) { cin >> C >> D; c = zzz(C); d = zzz(D); if (a == c) a = d; else if (b == c) b = d; else if (a == d) a = c; else if (b == d) b = c; xxx(a); cout << ' '; xxx(b); cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c, d; long long n; cin >> a >> b; cin >> n; cout << a << " " << b << "\n"; while (n) { n--; cin >> c >> d; if (c != a) { cout << a << " " << d << "\n"; b = d; } else { cout << d << " " << b << "\n"; a = d; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string str1, str2; cin >> str1 >> str2; int n; cin >> n; string str[2 * n]; for (int i = 0; i < 2 * n; i = i + 2) cin >> str[i] >> str[i + 1]; cout << str1 << " " << str2 << endl; for (int i = 0; i < 2 * n; i = i + 2) { if (str1 == str[i]) { cout << str2 << " " << str[i + 1]; str1 = str[i + 1]; } else { cout << str1 << " " << str[i + 1]; str2 = str[i + 1]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s1, s2; int main() { cin.sync_with_stdio(false); cin >> s1 >> s2; cin >> n; cout << s1 << " " << s2 << endl; for (int i = (int)(0); i < (int)(n); i++) { string k, a; cin >> k >> a; if (s1 == k) { s1 = a; } else { s2 = a; } cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; cout << s1 << " " << s2 << endl; int n; cin >> n; while (n--) { string s3, s4; cin >> s3 >> s4; if (s3 == s1) { cout << s2 << " " << s4 << endl; s1 = s2; s2 = s4; } else { cout << s1 << " " << s4 << endl; s2 = s4; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; string a, b, c, d; cin >> a >> b; cout << a << " " << b << endl; cin >> n; for (int i = 0; i < n; i++) { cin >> c >> d; if (b != c) { cout << b << " " << d << endl; a = d; } else { cout << a << " " << d << endl; b = d; } } }
#include <bits/stdc++.h> using namespace std; string s1, s2, t1, t2; int n; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); cin >> s1 >> s2; cin >> n; for (int i = 1; i <= n; i++) { cout << s1 << " " << s2 << "\n"; cin >> t1 >> t2; if (s1 == t1) s1 = t2; else s2 = t2; } cout << s1 << " " << s2; }
#include <bits/stdc++.h> using namespace std; int n; char two[2][11]; string first[1001]; string second[1001]; int main() { scanf("%s %s", two[0], two[1]); first[0] = string(two[0]); second[0] = string(two[1]); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s %s", two[0], two[1]); string f(two[0]); string s(two[1]); first[i + 1] = (first[i] == f ? second[i] : first[i]); second[i + 1] = s; } for (int i = 0; i <= n; i++) { cout << first[i] << " " << second[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int dayc; cin >> dayc; cout << a << " " << b << endl; for (int i = 0; i < dayc; i++) { string killed, newguy; cin >> killed >> newguy; if (killed == a) { a = newguy; } else { b = newguy; } cout << a << " " << b << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s[1005], ss[1005]; cin >> s[0] >> ss[0]; int n; cin >> n; for (int i = 1; i <= n; i++) cin >> s[i] >> ss[i]; for (int i = 0; i <= n; i++) { if (i == 0) { cout << s[0] << " " << ss[0] << endl; continue; } else if (s[i] == s[i - 1]) { s[i] = ss[i]; ss[i] = ss[i - 1]; cout << s[i] << " " << ss[i] << endl; } else if (s[i] == ss[i - 1]) { s[i] = s[i - 1]; cout << s[i] << " " << ss[i] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s1, s2, s3, s4; cin >> s1 >> s2; cout << s1 << " " << s2 << '\n'; long long int n; cin >> n; while (n--) { cin >> s3 >> s4; if (s3 == s1) { cout << s4 << " " << s2 << '\n'; s1 = s4; } else { cout << s1 << " " << s4 << '\n'; s2 = s4; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; char a[15], b[15], c[15]; scanf("%s%s", a, b); scanf("%d", &n); printf("%s %s\n", a, b); for (int i = 1; i <= n; i++) { scanf("%s", c); int l = strlen(c); int la = strlen(a); int lb = strlen(b); if (memcmp(a, c, l) == 0 && l == la) { scanf("%s", a); printf("%s %s\n", a, b); } if (memcmp(b, c, l) == 0 && l == lb) { scanf("%s", b); printf("%s %s\n", a, b); } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 1010; int n, m; char s1[MAX], s2[MAX]; int main() { int i, j, k, t; while (~scanf("%s%s", s1, s2)) { scanf("%d", &n); printf("%s %s\n", s1, s2); while (n--) { char c1[MAX], c2[MAX]; scanf("%s%s", c1, c2); if (strcmp(s1, c1) == 0) strcpy(s1, c2); else strcpy(s2, c2); printf("%s %s\n", s1, s2); } } }
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n; std::string s1, s2, st; std::cin >> s1 >> s2 >> n; for (int i = 0; i < n; ++i) { std::cout << s1 << ' ' << s2 << '\n'; std::cin >> st; if (st == s1) std::cin >> s1; else std::cin >> s2; } std::cout << s1 << ' ' << s2 << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string a, b, foo, bar; cin >> a >> b >> n; while (n--) { cout << a << " " << b << endl; cin >> foo >> bar; if (foo == a) a = bar; else b = bar; } cout << a << " " << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string a, b, c, f; int d; int main() { cin >> a >> b >> d; for (int e = 0; e < d; e++) { cout << a << " " << b << endl; cin >> c >> f; if (a == c) { a = f; } else { b = f; } } cout << a << " " << b << endl; return 0; }
#include <bits/stdc++.h> int main(void) { int n, i = 0; std::string first, second, third, fourth; std::cin >> first >> second >> n; std::cout << first << ' ' << second << '\n'; for (int i = 0; i < n; i++) { std::cin >> third >> fourth; if (third == first) { first = fourth; } else { second = fourth; } std::cout << first << ' ' << second << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s1, s2, s3, s4; int main() { cin >> s1 >> s2 >> n; cout << s1 << ' ' << s2 << endl; for (int i = 1; i <= n; ++i) { cin >> s3 >> s4; if (s1 == s3) s1 = s4; if (s2 == s3) s2 = s4; cout << s1 << ' ' << s2 << endl; } }
#include <bits/stdc++.h> using namespace std; set<string> s; int main() { string s1, s2; cin >> s1 >> s2; s.insert(s1); s.insert(s2); cout << s1 << " " << s2 << endl; int n; cin >> n; for (int i = 0; i < n; i++) { string t, p; cin >> t >> p; s.erase(t); s.insert(p); for (auto q : s) { cout << q << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; cout << a << ' ' << b << endl; int n; cin >> n; for (int i = 0; i < n; i++) { string c, d; cin >> c >> d; if (c == a) a = d; else b = d; cout << a << ' ' << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s[2], in[2]; cin >> s[0] >> s[1]; cin >> n; cout << s[0] << " " << s[1] << endl; for (int i = 0; i < n; i++) { cin >> in[0] >> in[1]; if (s[0] == in[0]) { s[0] = in[1]; } else { s[1] = in[1]; } cout << s[0] << " " << s[1] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct Killer { string killed; string potential; }; int getType(Killer killer, string val) { if (killer.killed == val) { return 0; } if (killer.potential == val) { return 1; } return -1; } int main() { int count; vector<Killer> kill; Killer killer; cin >> killer.killed; cin >> killer.potential; cin >> count; kill.push_back(killer); for (int i = 0; i < count; i++) { Killer tmpKiller; cin >> tmpKiller.killed; cin >> tmpKiller.potential; int type = getType(kill[i], tmpKiller.killed); if (type == 0) { Killer k; k.killed = tmpKiller.potential; k.potential = kill[i].potential; kill.push_back(k); } else { Killer k; k.killed = kill[i].killed; k.potential = tmpKiller.potential; kill.push_back(k); } } for (int i = 0; i < kill.size(); i++) { cout << kill[i].killed << " " << kill[i].potential << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, t; cin >> s >> t; int n; cin >> n; for (int i = 1; i <= n; i++) { cout << s << " " << t << endl; string p, g; cin >> p >> g; if (s == p) s = g; else t = g; } cout << s << " " << t << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, k, l, m, b, c; string s, h, o; cin >> s >> h; cin >> n; for (i = 0; i <= n; i++) { cout << s << " " << h << endl; if (i == n) return 0; cin >> o; if (o == s) { cin >> o; s = o; } else { cin >> o; h = o; } } }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4; int n, i; cin >> s1 >> s2; cout << s1 << " " << s2 << endl; cin >> n; for (i = 1; i <= n; i++) { cin >> s3 >> s4; if (s3 == s1) { s1 = s4; } else if (s3 == s2) { s2 = s4; } cout << s1 << " " << s2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n; char s[15], s1[15], l[15], k[15]; cin >> s >> s1; cin >> n; cout << s << " " << s1 << endl; while (n--) { cin >> k >> l; if (strcmp(k, s) == 0) { cout << l << " " << s1 << endl; strcpy(s, l); } else if (strcmp(k, s1) == 0) { cout << l << " " << s << endl; strcpy(s1, l); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n; string t, p, tt, pp; cin >> t >> p; cout << t << " " << p << endl; cin >> n; while (n--) { cin >> tt >> pp; if (t.compare(tt) == 0) t.assign(pp); else p.assign(pp); cout << t << " " << p << endl; } }
#include <bits/stdc++.h> const long long mxn = 1e5 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, d; long long n; cin >> s >> d; cin >> n; cout << s << ' ' << d << endl; ; for (int i = 0; i < n; i++) { string a, b; cin >> a >> b; if (a == s) { s = b; } else if (b != s) { d = b; } cout << s << ' ' << d << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { set<string> s; string a, b; cin >> a >> b; s.insert(a); s.insert(b); int n; cin >> n; cout << a << " " << b << endl; for (int i = (0); i < (n); ++i) { string c, d; cin >> c >> d; s.erase(s.find(c)); s.insert(d); for (__typeof((s).begin()) j = ((s).begin()); j != (s).end(); ++j) { cout << (*j) << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c, d; int n; cin >> a >> b; cin >> n; cout << a << " " << b << endl; for (int i = 0; i < n; i++) { cin >> c >> d; if (c == a) a = d; else if (c == b) b = d; else if (d == a) a = c; else if (d == b) b = c; cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, x, y; int n; cin >> a >> b >> n; n++; while (n--) { cout << a << " " << b << '\n'; cin >> x >> y; if (x == a) a = y; else if (x == b) b = y; } }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4, s; cin >> s1 >> s2; cout << s1 << " " << s2 << endl; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s3 >> s4; if (s1 == s3) { s = s2; s1 = s; s2 = s4; } else { s = s1; s1 = s; s2 = s4; } cout << s << " " << s4 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string s, d, f, g; int n; int main() { cin >> s >> d >> n; cout << s << " " << d << endl; for (int i = 0; i < n; i++) { cin >> f >> g; if (f == s) { s.erase(s.begin(), s.end()); s = g; cout << s << " " << d << endl; } else { d.erase(d.begin(), d.end()); d = g; cout << s << " " << d << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c, d; int t = 0, n = 0; cin >> a >> b; scanf("%d", &t); cout << a << " " << b << endl; while (t--) { cin >> c >> d; if (c == a) a = d; else if (c == b) b = d; else if (d == a) a = c; else b = c; cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); string second, t, x, y; int n; int main() { cin >> second >> t; string cur1 = second, cur2 = t; cin >> n; cout << second << " " << t << endl; for (int i = 0; i < n; ++i) { cin >> x >> y; if (cur1 == x) cur1 = y; else if (cur2 == x) cur2 = y; cout << cur1 << " " << cur2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char a[11], b[11], c[11], d[11]; scanf("%s%s", a, b); printf("%s %s\n", a, b); int n; scanf("%d", &n); for (int i = n; i > 0; i--) { scanf("%s %s", c, d); if (strcmp(c, a) == 0) strcpy(a, d); else strcpy(b, d); printf("%s %s\n", a, b); } return 0; }
#include <bits/stdc++.h> using namespace std; string a[1005], b[1005], p1, p2; int main() { int n, i; ios::sync_with_stdio(false); cin.tie(NULL); cin >> a[0] >> b[0]; cin >> n; cout << a[0] << " " << b[0] << endl; p1 = a[0]; p2 = b[0]; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (a[i] == p1) { p1 = p2; p2 = b[i]; } else { if (a[i] == p2) { p2 = p1; p1 = b[i]; } else { if (b[i] == p1) { p1 = p2; p2 = a[i]; } else { p2 = p1; p1 = a[i]; } } } cout << p1 << " " << p2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int n; cin >> n; string a, b; cout << s1 << " " << s2 << endl; for (int i = 0; i < n; i++) { cin >> a >> b; if (a == s1) s1 = b; else if (a == s2) s2 = b; else if (b == s1) s1 = a; else if (b == s2) s2 = a; cout << s1 << " " << s2 << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int main() { ios::sync_with_stdio(false); int n; string s, t; cin >> s >> t; cin >> n; cout << s << " " << t << "\n"; while (n--) { string a, b; cin >> a >> b; if (a == s) s = b; else t = b; cout << s << " " << t << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } int main() { char s1[15], s2[15], s[15]; int n; scanf("%s %s %d", s1, s2, &n); printf("%s %s\n", s1, s2); for (int i = 0; i < n; i++) { scanf("%s", s); if (!strcmp(s, s1)) scanf("%s", s1); else scanf("%s", s2); printf("%s %s\n", s1, s2); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4; long long int n; cin >> s1 >> s2; cin >> n; for (long long int i = 0; i < n; i++) { cout << s1 << " " << s2 << endl; cin >> s3 >> s4; if (s1.compare(s3) == 0) { s1 = s4; } else { s2 = s4; } } cout << s1 << " " << s2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int NIL = -1; template <class T> inline T mx(T a, T b) { return a > b ? a : b; } template <class T> inline T mi(T a, T b) { return a < b ? a : b; } template <class T> inline void sw(T &a, T &b) { T t = a; a = b; b = t; } template <class T> inline T mabs(T x) { return x < 0 ? -x : x; } inline char gc() { char ret; while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t') ; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); string str[2]; cin >> str[0] >> str[1]; string u, v; int n; cin >> n; cout << str[0] << ' ' << str[1] << '\n'; while (n--) { cin >> u >> v; for (int i = 0; i < 2; i++) { if (str[i] == u) str[i] = v; } cout << str[0] << ' ' << str[1] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; string s1, s2; while (cin >> s1 >> s2) { long long int n; cin >> n; vector<pair<string, string>> v; v.push_back({s1, s2}); for (long long int i = 1; i <= n; i++) { string s3, s4; cin >> s3 >> s4; if (s3 == v[i - 1].first) { v.push_back({s4, v[i - 1].second}); } else if (s3 == v[i - 1].second) { v.push_back({v[i - 1].first, s4}); } } for (long long int i = 0; i < v.size(); i++) { cout << v[i].first << " " << v[i].second << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int toint(string s) { int first = 0; int k = (int)pow(10, (double)s.length() - 1); for (int i = 0; i < (int)s.length(); i++) { first += (s[i] - '0') * k; k /= 10; } return first; } string tostr(int first) { if (first == 0) { return "0"; } string s = ""; bool f = first < 0; first = abs(first); while (first != 0) { s += (first % 10) + '0'; first /= 10; } string t = ""; if (f) { t = "-"; } for (int i = s.length() - 1; i >= 0; i--) { t += s[i]; } return t; } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int factorial(int first) { int sum = 1; for (long long i = 1; i <= first; i++) { sum *= i; } return sum; } bool pr(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } inline void out(int mas[], int s) { for (int i = 0; i < s; i++) { cout << mas[i] << endl; } } int sum(int n) { int first = 0; while (n) { first += n % 10; n /= 10; } return first; } inline int nxt() { int first; scanf("%d", &first); return first; } int main() { string s, s1; cin >> s >> s1; int n = nxt(); vector<pair<string, string> > mas(n); for (int i = 0; i < n; i++) cin >> mas[i].first >> mas[i].second; cout << s << " " << s1 << endl; for (int i = 0; i < n; i++) { if (s == mas[i].first) s = mas[i].second; else if (s1 == mas[i].first) s1 = mas[i].second; else if (s == mas[i].second) s = mas[i].first; else if (s1 == mas[i].second) s1 = mas[i].first; cout << s << " " << s1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int m, n; int main() { int n; string vic1, vic2, tmp1, tmp2; cin >> vic1 >> vic2; cin >> n; cout << vic1 << " " << vic2 << endl; for (int i = 0; i < n; ++i) { cin >> tmp1 >> tmp2; if (vic1 == tmp1) vic1 = tmp2; else vic2 = tmp2; cout << vic1 << " " << vic2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100050; string a, b, c; int n; int main() { cin.sync_with_stdio(false); cin >> a >> b >> n; for (int i = 1; i <= n; ++i) { cout << a << ' ' << b << endl; cin >> c; if (c == a) cin >> a; else cin >> b; } cout << a << ' ' << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string a, b, c; int main() { int n; cin >> a >> b; cout << a << " " << b << endl; cin >> n; while (n--) { cin >> c; if (c == a) cin >> a; else cin >> b; cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int eps = 1e-14; const int mod = 1e9 + 7; const long long inf = 1e18; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s1, s2; cin >> s1 >> s2; int n; cin >> n; cout << s1 << " " << s2 << endl; for (int i = 0; i < n; i++) { string dead, re; cin >> dead >> re; if (dead == s1) { s1 = re; } else { s2 = re; } cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; inline void boost() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } string cur1, cur2; int n; int main() { boost(); cin >> cur1 >> cur2; cout << cur1 << " " << cur2 << '\n'; cin >> n; for (int i = 1; i <= n; i++) { string dead, nw; cin >> dead >> nw; if (dead == cur1) cur1 = cur2, cur2 = nw; else cur2 = nw; cout << cur1 << " " << cur2 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int n; string name1, name2, name3, name4; cin >> name1 >> name2; cin >> n; for (int i = 0; i <= n; i++) { cout << name1 << " " << name2 << endl; cin >> name3 >> name4; if (name1.compare(name3) == 0) { name1 = name4; } else if (name2.compare(name3) == 0) { name2 = name4; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z, k, w; char A[15], B[15], C[15], D[15]; int check(char *A, char *B) { int x = strlen(A); int y = strlen(B); if (x != y) return 0; for (int i = (0); i < (x); i++) if (A[i] != B[i]) return 0; return 1; } void assign(char *A, char *B) { int x = strlen(B); for (int i = (0); i < (x); i++) A[i] = B[i]; } int main() { scanf("%s %s", &A, &B); scanf("%d", &n); printf("%s %s\n", A, B); while (n--) { scanf("%s %s", &C, &D); if (check(A, C) == 1) { memset(A, 0, sizeof(A)); assign(A, D); } else { memset(B, 0, sizeof(B)); assign(B, D); } printf("%s %s\n", A, B); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; string v1, v2, s1, s2; cin >> v1 >> v2 >> n; cout << v1 << " " << v2 << "\n"; while (n--) { cin >> s1 >> s2; if (s1 == v1) v1 = s2; else v2 = s2; cout << v1 << " " << v2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 0x7f7f7f7f; template <typename t> t read() { t x = 0; int f = 1; char c = getchar(); while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar(); return x * f; } template <typename t> void write(t x) { if (x < 0) { putchar('-'), write(-x); return; } if (x >= 10) write(x / 10); putchar(x % 10 + 48); } string a, b, ans[1010][2]; int n; int main() { cin >> ans[0][0] >> ans[0][1]; cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b; if (ans[i - 1][0] == a) { ans[i][0] = b; ans[i][1] = ans[i - 1][1]; } else { ans[i][1] = b; ans[i][0] = ans[i - 1][0]; } } for (int i = 0; i <= n; i++) cout << ans[i][0] << " " << ans[i][1] << endl; }
#include <bits/stdc++.h> using namespace std; char a[1000 + 10][15]; char b[1000 + 10][15]; char c1[15], c2[15]; int main() { int n; cin >> c1 >> c2; cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i <= n; i++) { cout << c1 << " " << c2 << endl; if (strcmp(c1, a[i]) == 0) strcpy(c1, b[i]); else strcpy(c2, b[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; string a, b; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b; cin >> n; cout << a << " " << b << '\n'; while (n--) { string x, y; cin >> x >> y; if (x == a) a = y; else b = y; cout << a << " " << b << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; char a[15], b[15], c[15], d[15]; int main() { scanf("%s%s", a, b); printf("%s %s\n", a, b); int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s%s", c, d); if (!strcmp(a, c)) strcpy(a, d); else strcpy(b, d); printf("%s %s\n", a, b); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; int n; cin.sync_with_stdio(false); set<string> s; while (cin >> a >> b) { s.clear(); s.insert(a); s.insert(b); cin >> n; cout << a << " " << b << endl; for (int i = 0; i < n; i++) { cin >> a >> b; s.erase(s.find(a)); s.insert(b); for (set<string>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> vi[200005]; vector<pair<long long, long long> > vii[200005]; int main() { string a, b; cin >> a >> b; cout << a << " " << b << endl; int n; cin >> n; while (n--) { string c, d; cin >> c >> d; if (a == c) { cout << b << " " << d << endl; ; a = d; } else { cout << a << " " << d << endl; b = d; } } }
#include <bits/stdc++.h> using namespace std; const int maxn = 20; string a; string b; string x; string y; int main() { int n; cin >> a; cin >> b; cout << a << ' ' << b << endl; cin >> n; for (int i = 1; i <= n; i++) { cin >> x >> y; if (x == a) a = b, b = y; else b = y; cout << a << ' ' << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 10005; map<string, bool> map1; int main() { int n; string a, b, x, y; cin >> a >> b; map1[a] = false; map1[b] = false; cin >> n; cout << a << " " << b << endl; for (int i = 0; i < n; i++) { cin >> x >> y; map1[x] = true; if (!map1[a]) { cout << a << " " << y << endl; b = y; } else { cout << y << " " << b << endl; a = y; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s1, s2, s3, s4; cin >> s1 >> s2; int n; cin >> n; while (n--) { cout << s1 << " " << s2 << "\n"; cin >> s3 >> s4; if (s3 == s1) { s1 = s4; } else { s2 = s4; } } cout << s1 << " " << s2 << "\n"; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; vector<int> arr[N]; bool vis[N]; signed main() { string x, y; cin >> x >> y; cout << x << " " << y << endl; int n; cin >> n; while (n--) { string a, b; cin >> a >> b; if (x == a) { x = b; } else { y = b; } cout << x << " " << y << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)(8e18); const long long int MOD = 1e9 + 7; const int maxn = 100010; int main() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; int n; cin >> n; cout << a << ' ' << b << '\n'; for (int i = 0; i < n; i++) { string x, y; cin >> x >> y; if (x == a || x == b) { if (x == a) { cout << y << ' ' << b << '\n'; a = y; } else { cout << y << ' ' << a << '\n'; b = y; } } else { if (y == a) { cout << x << ' ' << b << '\n'; a = x; } else { cout << x << ' ' << a << '\n'; b = x; } } } }
#include <bits/stdc++.h> using namespace std; const int M = INT32_MAX; const int NMAX = 10007; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.precision(30); string z[2]; cin >> z[0] >> z[1]; int n; cin >> n; cout << z[1] << ' ' << z[0] << endl; for (int i = 0; i < n; i++) { string k, next; cin >> k >> next; if (k == z[1]) z[1] = next; else z[0] = next; cout << z[1] << ' ' << z[0] << endl; } return 0; };
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int n; cout << a << ' ' << b << endl; scanf("%d", &n); for (int i = 1; i <= n; ++i) { string c, d; cin >> c >> d; if (a == c) a = d; else if (b == c) b = d; cout << a << ' ' << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4; int n; cin >> s1 >> s2; cin >> n; cout << s1 << " " << s2 << endl; for (int i = 0; i < n; i++) { cin >> s3 >> s4; if (s3 == s1) { s1 = s4; } else s2 = s4; cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, x, y, m, o; int n; cin >> s1 >> s2; cin >> n; vector<pair<string, string> > v1; m = s1; o = s2; for (int i = 0; i < n; i++) { cin >> x >> y; if (x == s1) { v1.push_back(make_pair(y, s2)); s1 = y; } else { v1.push_back(make_pair(y, s1)); s2 = y; } } cout << m << " " << o << endl; vector<pair<string, string> >::iterator it = v1.begin(); while (it != v1.end()) { cout << it->first << " " << it->second << endl; it++; } }
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::string s1, s2; std::cin >> s1 >> s2; std::cout << s1 << " " << s2 << "\n"; int n; std::cin >> n; while (n--) { std::string a, b; std::cin >> a >> b; if (a == s1) { s1 = b; } else { s2 = b; } std::cout << s1 << " " << s2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s1[100], s2[100], t1[100], t2[100]; cin >> s1 >> s2; int n; cin >> n; char s[100], d[100]; cout << s1 << " " << s2 << endl; while (n--) { cin >> t1 >> t2; int i = 0; if (strcmp(s1, t1) == 0) { for (i = 0; i < strlen(t2); i++) { s1[i] = t2[i]; } s1[i] = NULL; } else { for (i = 0; i < strlen(t2); i++) { s2[i] = t2[i]; } s2[i] = NULL; } cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int n; cin >> n; cout << a << " " << b << endl; for (int i = 0; i < n; i++) { string c, d; cin >> c >> d; if (c == a) a = d; else b = d; cout << a << " " << b << endl; } }
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); int n; string a, b, second[10020], t[10020]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> a >> b; cin >> n; for (int i = 0; i < n; ++i) { cin >> second[i] >> t[i]; } for (int i = 0; i < n; ++i) { if (a == second[i]) { a = t[i]; cout << second[i] << " " << b << endl; } else { if (a == t[i]) { a = second[i]; cout << t[i] << " " << b << endl; } else { if (b == second[i]) { b = t[i]; cout << a << " " << second[i] << endl; } else { b = second[i]; cout << a << " " << t[i] << endl; } } } } cout << a << " " << b << endl; }
#include <bits/stdc++.h> using namespace std; double maxd(double a, double b) { if (a >= b) { return a; } return b; } double mind(double a, double b) { if (a <= b) { return a; } return b; } long long gcd(long long a, long long b) { if (a < b) { swap(a, b); } while (b) { long long r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int isPrim(int a) { if (a == 1) { return 0; } for (int i = 2; i <= (a + 1) / 2; i++) { if (a % i == 0) { return 0; } } return 1; } long long mod_pow(long long x, long long n, long long mod) { long long ret = 1; while (n > 0) { if (n % 2 == 1) { ret = (ret * x) % mod; } x = (x * x) % mod; n = n / 2; } return ret; } struct XX { int u; int v; int t; }; class xxIntu { public: bool operator()(const XX& riLeft, const XX& riRight) const { if ((riLeft.t) == (riRight.t)) { return riLeft.u < riRight.u; } return (riLeft.t) < (riRight.t); } }; int index(string in) { if (in == "A") { return 0; } else if (in == "B") { return 1; } else if (in == "C") { return 2; } else if (in == "D") { return 3; } else if (in == "E") { return 4; } else if (in == "F") { return 5; } else if (in == "G") { return 6; } else if (in == "H") { return 7; } else if (in == "I") { return 8; } else if (in == "J") { return 9; } else if (in == "K") { return 10; } else if (in == "L") { return 11; } else if (in == "M") { return 12; } else if (in == "N") { return 13; } else if (in == "O") { return 14; } else if (in == "P") { return 15; } else if (in == "Q") { return 16; } else if (in == "R") { return 17; } else if (in == "S") { return 18; } else if (in == "T") { return 19; } else if (in == "U") { return 20; } else if (in == "V") { return 21; } else if (in == "W") { return 22; } else if (in == "X") { return 23; } else if (in == "Y") { return 24; } else if (in == "Z") { return 25; } return -1; } string rindex(int in) { if (in == 65) { return "A"; } else if (in == 66) { return "B"; } else if (in == 67) { return "C"; } else if (in == 68) { return "D"; } else if (in == 69) { return "E"; } else if (in == 70) { return "F"; } else if (in == 71) { return "G"; } else if (in == 72) { return "H"; } else if (in == 73) { return "I"; } else if (in == 74) { return "J"; } else if (in == 75) { return "K"; } else if (in == 76) { return "L"; } else if (in == 77) { return "M"; } else if (in == 78) { return "N"; } else if (in == 79) { return "O"; } else if (in == 80) { return "P"; } else if (in == 81) { return "Q"; } else if (in == 82) { return "R"; } else if (in == 83) { return "S"; } else if (in == 84) { return "T"; } else if (in == 85) { return "U"; } else if (in == 86) { return "V"; } else if (in == 87) { return "W"; } else if (in == 88) { return "X"; } else if (in == 89) { return "Y"; } else if (in == 90) { return "Z"; } return ""; } int ppar[200001]; int rrank[200001]; void init(int n) { for (int i = 1; i <= n; i++) { ppar[i] = i; rrank[i] = 0; } } int find(int x) { if (ppar[x] == x) { return x; } else { return ppar[x] = find(ppar[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rrank[x] < rrank[y]) { ppar[x] = ppar[y]; } else { ppar[y] = x; if (rrank[x] == rrank[y]) { rrank[x]++; } } } bool same(int x, int y) { return find(x) == find(y); } struct edge { int u; int v; int cost; }; bool comp(edge& e1, edge& e2) { return e1.cost < e2.cost; } edge es[1000]; int V, E; int ans = 0; int kruskal() { sort(es, es + E, comp); init(V); int res = 0; for (int i = 0; i < E; i++) { edge e = es[i]; if (!same(e.u, e.v)) { unite(e.u, e.v); res += e.cost; ans++; } } return res; } int main(int argc, const char* argv[]) { string s1, s2; int n; cin >> s1 >> s2 >> n; string kil[1000]; string rep[1000]; for (int i = 0; i < n; i++) { cin >> kil[i] >> rep[i]; } cout << s1 << " " << s2 << endl; for (int i = 0; i < n; i++) { if (s1 == kil[i]) { s1 = rep[i]; } else { s2 = rep[i]; } cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a; string r, s; cin >> r >> s; cout << r << " " << s << endl; cin >> a; for (; a--;) { string u, v; cin >> u >> v; (u == r) ? r = v : s = v; cout << r << " " << s << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; list<string> l; string res = ""; int n; cin >> a >> b; l.push_back(a); l.push_back(b); cin >> n; for (int i = 0; i < n; i++) { string killed, potential; cin >> killed >> potential; for (list<string>::iterator it = l.begin(); it != l.end(); it++) { res += *it + " "; } res += "\n"; l.remove(killed); l.push_back(potential); } for (list<string>::iterator it = l.begin(); it != l.end(); it++) { res += *it + " "; } res += "\n"; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string choice1, choice2; cin >> choice1 >> choice2; cout << choice1 << " " << choice2 << "\n"; int n; cin >> n; string killed, survived; for (int i = 0; i < n; i++) { cin >> killed >> survived; if (choice1 == killed) { cout << choice2 << " " << survived << "\n"; choice1 = survived; } else { cout << choice1 << " " << survived << "\n"; choice2 = survived; } } }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; int n; string a, b, s; int main() { cin >> a >> b; cin >> n; cout << a << " " << b << endl; for (int i = 1; i <= n; i++) { cin >> s; if (a == s) { cin >> s; a = s; } else { cin >> s; b = s; } cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { set<string> s; string s1, s2; cin >> s1 >> s2; s.insert(s1); s.insert(s2); cout << s1 << " " << s2 << endl; int n; cin >> n; for (int i = 0; i < n; i++) { string x, y; cin >> x >> y; if (s.find(x) != s.end()) { s.erase(x); s.insert(y); } else if (s.find(y) != s.end()) { s.erase(y); s.insert(x); } else { continue; } set<string>::iterator it; for (it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s1, s2; cin >> s1 >> s2; int n; cout << s1 << " " << s2 << '\n'; cin >> n; string s3, s4; for (int i = 1; i <= n; i++) { cin >> s3 >> s4; cout << s4 << " "; if (s3 == s1) { cout << s2; s1 = s4; } else { cout << s1; s2 = s4; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n; cout << s << " " << t << endl; cin >> n; for (int i = 1; i <= n; i++) { string a, b; cin >> a >> b; if (s == a) s = b; if (t == a) t = b; cout << s << " " << t << endl; } }
#include <bits/stdc++.h> using namespace std; int n; string s1, s2, a, b; int main() { cin >> s1 >> s2; cin >> n; for (int i = 1; i <= n + 1; i++) { cin >> a >> b; cout << s1 << " " << s2 << endl; if (a == s1) { s1 = b; } else { s2 = b; } } }
#include <bits/stdc++.h> using namespace std; int main() { string s, t, m, r; int n; cin >> s >> t; cout << s << " " << t << endl; cin >> n; while (n--) { cin >> m >> r; if (m == s) s = r; else t = r; cout << s << " " << t << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, i; int main() { string a, b, c, d; cin >> a >> b; cin >> n; cout << a << " " << b << endl; for (i = 0; i < n; i++) { cin >> c >> d; if (a == c) { a = d; } else b = d; cout << a << " " << b << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s, c, m, b; cin >> s >> c; long long n; cin >> n; cout << s << " " << c << endl; for (int i = 0; i < n; i++) { cin >> m >> b; if (m == s) { s = b; } else { c = b; } cout << s << " " << c << endl; } }
#include <bits/stdc++.h> using namespace std; string s, t, a, b; int n; int main() { ios_base::sync_with_stdio(0); cin >> s >> t; cin >> n; cout << s << " " << t << endl; for (int i = 1; i <= n; i++) { cin >> a >> b; if (a == t) t = b; else if (a == s) s = b; else if (b == t) t = a; else if (b == s) s = a; cout << s << " " << t << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 500005; const long long mod = 1e9 + 7; void solve() { long long c = 0, ans = 0; long long n, m, k; string s, t, x, y; cin >> s >> t >> n; cout << s << " " << t << "\n"; for (long long i = 0; i < n; ++i) { cin >> x >> y; if (x == s) { cout << t << " " << y << "\n"; s = y; } else if (x == t) { cout << s << " " << y << "\n"; t = y; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int n; cin >> n; cout << a << " " << b << endl; while (n-- > 0) { string old, nw; cin >> old >> nw; if (a == old) a = nw; else b = nw; cout << a << " " << b << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s1; string s2; string victim; string replace; short n; cin >> s1 >> s2 >> n; cout << s1 << " " << s2 << endl; for (short i = 0; i < n; i++) { cin >> victim >> replace; if (victim == s1) s1 = replace; else s2 = replace; cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> char s1[22], s2[22], ns1[22], ns2[22]; int main() { int n, len1, len2, nlen1, nlen2; scanf("%s %s %d", s1, s2, &n); len1 = strlen(s1); len2 = strlen(s2); printf("%s %s\n", s1, s2); for (int i = 0; i < n; i++) { scanf("%s %s", ns1, ns2); nlen1 = strlen(ns1); nlen2 = strlen(ns2); if (len1 == nlen1) { bool sta = 1; for (int i = 0; i < len1; i++) { if (s1[i] != ns1[i]) { sta = 0; break; } } if (sta) { printf("%s %s\n", s2, ns2); for (int i = 0; i <= len1; i++) s1[i] = 0; for (int i = 0; i <= nlen2; i++) s1[i] = ns2[i]; len1 = nlen2; continue; } } if (len2 == nlen1) { bool sta = 1; for (int i = 0; i < len2; i++) { if (s2[i] != ns1[i]) { sta = 0; break; } } if (sta) { printf("%s %s\n", s1, ns2); for (int i = 0; i <= len2; i++) s2[i] = 0; for (int i = 0; i <= nlen2; i++) s2[i] = ns2[i]; len2 = nlen2; continue; } } } return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long powmod(long long a, long long b) { long long res = 1; if (a >= 1000000007) a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a; if (res >= 1000000007) res %= 1000000007; a = a * a; if (a >= 1000000007) a %= 1000000007; } return res; } static bool cmp(pair<long long, long long>& a, pair<long long, long long>& b) { return (a.second == b.second) ? a.first > b.first : a.second < b.second; } void solve() { set<string> s; string s1; cin >> s1; string s2; cin >> s2; s.insert(s1); s.insert(s2); cout << s1 << " " << s2 << endl; long long q; cin >> q; while (q--) { string x, y; cin >> x >> y; auto it = s.find(x); auto it2 = s.find(y); if (it != s.end()) { s.erase(x); s.insert(y); } if (it2 != s.end()) { s.erase(y); s.insert(x); } for (auto x : s) { cout << x << " "; } cout << endl; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); { solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string m, n, p, q; int i; cin >> m >> n; cout << m << " " << n << endl; cin >> i; for (; i > 0; i--) { cin >> p >> q; if (p == m) m = q; else if (p == n) n = q; else if (q == m) m = p; else n = p; cout << m << " " << n << endl; } }
#include <bits/stdc++.h> using namespace std; void solve() { string s1, s2; cin >> s1 >> s2; int n; cin.ignore(); cin >> n; cin.ignore(); string s[n], ss[n]; for (int i = 0; i < n; i++) { cin >> s[i] >> ss[i]; } cout << s1 << " " << s2 << endl; for (int i = 0; i < n; i++) { if (s1 == s[i]) { s[i] = s2; } else if (s1 == ss[i]) { ss[i] = s2; } else if (s2 == s[i]) { s[i] = s1; } else ss[i] = s1; cout << s[i] << " " << ss[i] << endl; s1 = s[i], s2 = ss[i]; } } int main() { ios::sync_with_stdio(0); cin.tie(0); { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; char a[3][11], vic[11], rep[11]; int n; void movee() { int i, lena = strlen(a[1]), lenb = strlen(vic); if (lena == lenb) { for (i = 0; i < lenb; i++) if (a[1][i] != vic[i]) break; if (i == lenb) memset(a[1], 0, sizeof(a[1])); else memset(a[2], 0, sizeof(a[2])); } else memset(a[2], 0, sizeof(a[2])); } void add() { int i, j; if (a[1][0] == 0) { for (i = 0; rep[i]; i++) a[1][i] = rep[i]; } else { for (i = 0; rep[i]; i++) a[2][i] = rep[i]; } } int main() { int i; scanf("%s%s", a[1], a[2]); scanf("%d", &n); printf("%s %s\n", a[1], a[2]); for (i = 1; i <= n; i++) { scanf("%s%s", vic, rep); movee(); add(); printf("%s %s\n", a[1], a[2]); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4; cin >> s1 >> s2; long long n; cin >> n; cout << s1 << " " << s2 << endl; while (n--) { cin >> s3 >> s4; if (s3 == s1) s1 = s4; else s2 = s4; cout << s1 << " " << s2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int size; string name1, name2, temp; vector<string> res; cin >> name1 >> name2 >> size; res.push_back(name1); res.push_back(name2); for (int i = 0; i < size; i++) { cin >> temp; if (temp == name1) { cin >> name1; res.push_back(name1); res.push_back(name2); } else { cin >> name2; res.push_back(name1); res.push_back(name2); } } for (int i = 0; i < res.size() - 1; i += 2) { cout << res[i] << " " << res[i + 1] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int n, i, k; cin >> n; cout << s1 << " " << s2 << endl; for (i = 0; i < n; i++) { string s3, s4; cin >> s3 >> s4; if (s3 == s1) k = 1; if (s3 == s2) k = 2; if (k == 1) cout << s4 << " " << s2 << endl; if (k == 2) cout << s1 << " " << s4 << endl; if (k == 1) s1 = s4; if (k == 2) s2 = s4; } }
#include <bits/stdc++.h> using namespace std; int main() { set<string> victims; string p1, p2; cin >> p1 >> p2; victims.insert(p1); victims.insert(p2); cout << p1 << " " << p2 << endl; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> p1 >> p2; victims.erase(p1); set<string>::iterator iter = victims.begin(); cout << *iter << " "; cout << p2 << endl; victims.insert(p2); } return 0; }
#include <bits/stdc++.h> using namespace std; string a, b; string c, d; int main() { cin >> a >> b; cout << a << " " << b << endl; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> c >> d; if (c == a) { a = d; } else { b = d; } cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string s1, s2, s3, s4; int n; int main() { cin >> s1 >> s2; cin >> n; cout << s1 << " " << s2 << endl; for (int i = 1; i <= n; i++) { cin >> s3 >> s4; if (s3 == s1) s1 = s4; else s2 = s4; cout << s1 << " " << s2 << endl; ; } }
#include <bits/stdc++.h> using namespace std; int main() { string str1[1][2]; for (int i = 0; i < 2; i++) { cin >> str1[0][i]; } int n; cin >> n; string str2[n][2]; string str3[n + 1][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) cin >> str2[i][j]; } str3[0][0] = str1[0][0]; str3[0][1] = str1[0][1]; for (int i = 0; i < n; i++) { if (str2[i][0] == str3[i][0]) { str3[i + 1][0] = str2[i][1]; str3[i + 1][1] = str3[i][1]; } else if (str2[i][0] == str3[i][1]) { str3[i + 1][0] = str2[i][1]; str3[i + 1][1] = str3[i][0]; } } for (int i = 0; i < n + 1; i++) { cout << str3[i][0] << " " << str3[i][1] << endl; } return 0; }