text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
const long long int mod = 1e9 + 7;
using namespace std;
bool prime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
string s1, s2;
cin >> s1 >> s2;
map<string, long long int> v;
v[s1]++;
v[s2]++;
long long int n;
cin >> n;
while (n--) {
for (auto x : v) {
if (x.second) cout << x.first << " ";
}
string s3, s4;
cin >> s3 >> s4;
if (v[s3]) {
v[s3] = 0;
} else
v[s3]++;
if (v[s4])
v[s4] = 0;
else
v[s4]++;
cout << '\n';
}
for (auto x : v) {
if (x.second) cout << x.first << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, l = 0, r = 0;
string s2, s1, s3, s4;
long a[4][4];
int main() {
cin >> s1 >> s2 >> 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() {
ios_base::sync_with_stdio(false);
string a, b;
cin >> a >> b;
short n;
cin >> n;
string res[n + 1];
res[0] = a + " " + b;
for (int i = 1; i <= n; ++i) {
string m, r;
cin >> m >> r;
if (m == a)
a = r;
else
b = r;
res[i] = a + " " + b;
}
for (int i = 0; i < n + 1; ++i) cout << res[i] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long i, j, n, t = 1, k = 0, cnt = 0, mini = LLONG_MAX, maxi = LLONG_MIN,
ans = 0;
long long m;
string a, b;
cin >> a >> b;
cin >> n;
cout << a << " " << b << '\n';
for (i = 0; i < n; i++) {
string s, f;
cin >> s >> f;
if (a == s)
a = f;
else
b = f;
cout << a << " " << b << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, m, n, p, x, y;
string s1, s2, s3, s4;
cin >> s1 >> s2;
cin >> n;
cout << s1 << " " << s2;
cout << endl;
for (i = 0; i < n; i++) {
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
cout << s1 << " " << s2;
}
if (s3 == s2) {
s2 = s4;
cout << s1 << " " << s2;
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0) return a;
return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
long long gcd = GCD(a, b);
return (a * b) / gcd;
}
int main() {
long long i, j, k, n, m, t, x, y, s = 0;
string a, b, c, d;
cin >> a >> b >> n;
cout << a << " " << b << endl;
while (n--) {
cin >> c >> d;
if (c == a) {
a = d;
cout << a << " " << b << endl;
} else if (c == b) {
b = d;
cout << a << " " << b << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t, s1, t1;
cin >> s >> t;
int n;
cin >> n;
cout << s << " " << t << endl;
while (n--) {
cin >> s1 >> t1;
if (s1 == s) {
cout << t << " " << t1 << endl;
s = t;
t = t1;
} else if (s1 == t) {
cout << s << " " << t1 << endl;
t = t1;
} else if (t1 == s) {
cout << t << " " << s1 << endl;
s = t;
t = s1;
} else if (t1 == t) {
cout << s << " " << s1 << endl;
t = s1;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
cout << s << ' ' << t << '\n';
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string x, y;
cin >> x >> y;
if (x == s) {
s = y;
} else if (x == t) {
t = y;
} else if (y == s) {
s = x;
} else if (y == t) {
t = x;
}
cout << s << ' ' << t << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << s1 << " " << s2 << endl;
string t1, t2;
cin >> t1 >> t2;
if (t1 == s1)
s1 = t2;
else
s2 = t2;
}
cout << s1 << " " << s2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int i, n;
cin >> a >> b;
cin >> n;
string ar[n][2], tmp, tmp1;
for (i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> ar[i][j];
}
}
cout << a << " " << b << endl;
for (i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
if (i == 0) {
if (ar[i][0] == a) {
tmp = b;
tmp1 = ar[i][1];
} else {
tmp = a;
tmp1 = ar[i][1];
}
} else {
if (ar[i][0] == tmp) {
tmp = ar[i][1];
} else if (ar[i][0] == tmp1) {
tmp1 = ar[i][1];
}
}
}
cout << tmp << " " << tmp1 << endl;
}
}
|
#include <bits/stdc++.h>
#pragma GCC target("sse4,avx")
void run(std::istream &in, std::ostream &out) {
std::string a, b;
in >> a >> b;
int n;
in >> n;
out << a << " " << b << std::endl;
for (int i = 0; i < n; i++) {
std::string murdered, replaced;
in >> murdered >> replaced;
if (murdered == a) {
a = replaced;
} else {
b = replaced;
}
out << a << " " << b << std::endl;
}
}
int main() {
std::cin.sync_with_stdio(false);
std::cin.tie(nullptr);
run(std::cin, std::cout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1000000007;
const double pi = acos(-1.0);
inline void gn(long long& x) {
int sg = 1;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
c == '-' ? (sg = -1, x = 0) : (x = c - '0');
while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
x *= sg;
}
inline void gn(int& x) {
long long t;
gn(t);
x = t;
}
inline void gn(unsigned long long& x) {
long long t;
gn(t);
x = t;
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long x, long long mod) {
long long t = 1ll;
while (x) {
if (x & 1) t = t * a % mod;
a = a * a % mod;
x >>= 1;
}
return t;
}
int main() {
string a, b;
cin >> a >> b;
int n;
cin >> n;
for (int i = (1); i <= (n); i++) {
cout << a << " " << b << endl;
string ol, ne;
cin >> ol >> ne;
if (a == ol)
a = ne;
else
b = ne;
}
cout << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c, d;
int n;
cin >> a >> b >> n;
cout << a << " " << b << endl;
for (int i = 0; i < n; i++) {
cin >> c >> d;
if (c == a) {
cout << d << " " << b << endl;
a = d;
} else if (c == b) {
cout << a << " " << d << endl;
b = d;
} else if (d == a) {
cout << c << " " << b << endl;
a = c;
} else {
cout << a << " " << c << endl;
d = c;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long powermod(long long _a, long long _b, long long _m) {
long long _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;
}
return _r;
}
long long string_to_number(string s) {
long long x = 0;
stringstream convert(s);
convert >> x;
return x;
}
long long add(long long a, long long b) {
long long x = (a + b) % 1000000007;
return x;
}
long long mul(long long a, long long b) {
long long x = (a * b) % 1000000007;
return x;
}
long long sub(long long a, long long b) {
long long x = (a - b + 1000000007) % 1000000007;
return x;
}
long long divi(long long a, long long b) {
long long x = a;
long long y = powermod(b, 1000000007 - 2, 1000000007);
long long res = (x * y) % 1000000007;
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
cout << s1 << " " << s2 << '\n';
while (n--) {
string a, b;
cin >> a >> b;
if (s1 == a)
s1 = b;
else
s2 = b;
cout << s1 << " " << s2 << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> vec;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s1, s2;
int n;
cin >> s1 >> s2;
cin >> n;
string s3, s4;
cout << s1 << " " << s2 << endl;
cin >> s3 >> s4;
if (s1 == s3)
s1 = s4;
else if (s3 == s2)
s2 = s4;
cout << s1 << " " << s2 << endl;
for (int i = 0; i < n - 1; i++) {
cin >> s3 >> s4;
if (s1 == s3)
s1 = s4;
else if (s3 == s2)
s2 = s4;
cout << s1 << " " << s2 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, o;
cin >> s >> o;
int n;
cin >> n;
cout << s << ' ' << o << '\n';
string x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
if (x == s) {
s = y;
} else {
o = y;
}
cout << s << ' ' << o << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string x, y, x1, y1;
cin >> x >> y;
cin >> n;
for (int i = 0; i < n + 1; i++) {
cout << x << " " << y << endl;
if (i == n) continue;
cin >> x1 >> y1;
if (x1 == x)
x = y1;
else
y = y1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, m, n;
string a[1010], b[1010], x, y;
cin >> a[0] >> b[0] >> n;
for (i = 1; i <= n; i++) {
cin >> x >> y;
if (x == a[i - 1]) {
a[i] = y;
b[i] = b[i - 1];
} else {
a[i] = a[i - 1];
b[i] = y;
}
}
for (i = 0; i <= n; i++) {
cout << a[i] << " " << b[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, x;
string f, s;
cin >> f >> s;
cin.ignore();
cin >> n;
cout << f << " " << s << "\n";
for (i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
if (a == f)
f = b;
else if (a == s)
s = b;
cout << f << " " << s << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int n;
cin >> a >> b >> n;
string a1[n], b1[n], sol[n + 1], sol1[n + 1];
sol[0] = a;
sol1[0] = b;
for (int i = 0; i < n; i++) {
cin >> a1[i] >> b1[i];
if (i == 0) {
if (a1[i] == a) {
sol[i + 1] = b1[i];
sol1[i + 1] = b;
} else if (a1[i] == b) {
sol[i + 1] = a;
sol1[i + 1] = b1[i];
}
} else {
if (a1[i] == sol[i]) {
sol[i + 1] = b1[i];
sol1[i + 1] = sol1[i];
} else {
sol1[i + 1] = b1[i];
sol[i + 1] = sol[i];
}
}
}
for (int u = 0; u < n + 1; u++) {
cout << sol[u] << " " << sol1[u] << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
vector<pair<string, string>> ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string f, s;
cin >> f >> s;
int n;
cin >> n;
ans.push_back({f, s});
for (int i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
if (a == f) {
ans.push_back({b, s});
f = b;
} else {
ans.push_back({f, b});
s = b;
}
}
for (int i = 0; i < n + 1; i++)
cout << ans[i].first << " " << ans[i].second << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
string alive[1005], dead[1005], c, d;
cin >> c >> d;
cin >> n;
for (i = 1; i < n + 1; i++) {
cin >> dead[i] >> alive[i];
}
dead[0] = c;
alive[0] = d;
cout << c << " " << d << "\n";
for (i = 1; i < n + 1; i++) {
if (dead[i] == dead[0]) {
dead[0] = alive[i];
} else if (dead[i] == alive[0]) {
alive[0] = alive[i];
}
cout << dead[0] << " " << alive[0] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
int arr[100005];
int main() {
char a[15], b[15], c[15], d[15];
scanf("%s %s", &a, &b);
int n;
scanf("%d", &n);
printf("%s %s\n", a, b);
while (n--) {
scanf("%s %s", &c, &d);
if (strcmp(a, c) == 0)
strcpy(a, d);
else
strcpy(b, d);
printf("%s %s\n", a, b);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, i;
string s1, s2, s3, s4;
vector<long long> v;
map<long long, long long> m;
int main() {
cin >> s1 >> s2;
cin >> n;
cout << s1 << " " << s2 << endl;
for (i = 1; i <= n; i++) {
cin >> s3 >> s4;
if (s1 == s3) {
cout << s4 << " " << s2 << endl;
s1 = s4;
} else {
cout << s1 << " " << s4 << endl;
s2 = s4;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str1[15], str2[15];
while (~scanf("%s%s", str1, str2)) {
int n, m, i, j, k, l;
char str3[15], str4[15];
scanf("%d", &n);
printf("%s %s\n", str1, str2);
for (i = 0; i < n; i++) {
scanf("%s%s", str3, str4);
if (strcmp(str1, str3) == 0)
strcpy(str1, str4);
else if (strcmp(str2, str3) == 0)
strcpy(str2, str4);
printf("%s %s\n", str1, str2);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int n;
cin >> n;
string a1, b1;
cout << a << " " << b << '\n';
while (n--) {
cin >> a1 >> b1;
if (a == a1)
swap(a, b1);
else
swap(b, b1);
cout << a << " " << b << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int block_size = 320;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const int inf = mod;
const double PI = atan(1) * 4;
template <typename T>
inline int sign(const T &a) {
if (a < 0) return -1;
if (a > 0) return 1;
return 0;
}
template <typename T>
inline void in(T &x) {
x = 0;
T f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
template <typename A, typename B>
inline void in(A &x, B &y) {
in(x);
in(y);
}
template <typename A, typename B, typename C>
inline void in(A &x, B &y, C &z) {
in(x);
in(y);
in(z);
}
template <typename A, typename B, typename C, typename D>
inline void in(A &x, B &y, C &z, D &xx) {
in(x);
in(y);
in(z);
in(xx);
}
template <class T>
void upd(T &a, T &b) {
a = max(a, b);
}
set<string> s;
void pr() {
for (auto i : s) cout << i << ' ';
cout << endl;
}
int main() {
string a, b;
cin >> a >> b;
s.insert(a);
s.insert(b);
pr();
int n;
cin >> n;
for (long long i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
s.erase(a);
s.insert(b);
pr();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string name1, name2;
void print() {
cout << name1 << " " << name2 << endl;
return;
}
int main() {
int n;
string k, r;
cin >> name1 >> name2;
cin >> n;
print();
for (int i = 0; i < n; i++) {
cin >> k >> r;
if (k == name1)
name1 = r;
else if (k == name2)
name2 = r;
print();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s3, s4;
cin >> s1 >> s2;
cout << s1 << " " << s2 << endl;
int n, i;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
cout << s1 << " " << s2 << endl;
} else if (s3 == s2) {
s2 = s4;
cout << s1 << " " << s2 << endl;
} else if (s4 == s1) {
s4 = s2;
cout << s3 << " " << s4 << endl;
} else if (s4 == s2) {
s4 = s1;
cout << s3 << " " << s4 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000006];
int main() {
int n;
string a, b, c, d;
cin >> a >> b;
scanf("%d", &n);
cout << a << " " << b << "\n";
while (n--) {
cin >> c >> d;
if (c.compare(a) == 0)
a = d;
else if (c.compare(b) == 0)
b = d;
else if (d.compare(a) == 0)
a = c;
else
b = c;
cout << a << " " << b << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, m, x = 0, t, ans = 0, sum = 0;
string s, a, b;
bool f = 0, flag = 0;
map<string, bool> mm;
cin >> a >> b;
mm[a] = 1;
mm[b] = 1;
cin >> n;
cout << a << " " << b << endl;
for (i = 0; i < n; i++) {
cin >> a >> b;
mm[a] = 0;
map<string, bool>::iterator it;
for (it = mm.begin(); it != mm.end(); it++) {
if (mm[it->first] == 1) {
cout << it->first;
break;
}
}
cout << " " << b << "\n";
mm[b] = 1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string arr[10004][2];
int n;
int main() {
cin >> arr[0][0] >> arr[0][1] >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i][0] >> arr[i][1];
if (arr[i][0] == arr[i - 1][0]) {
arr[i][0] = arr[i][1];
arr[i][1] = arr[i - 1][1];
} else if (arr[i][0] == arr[i - 1][1]) {
arr[i][0] = arr[i - 1][0];
}
}
for (int i = 0; i <= n; i++) {
cout << arr[i][0] << " " << arr[i][1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string ans[5];
int main() {
ios::sync_with_stdio(false);
string s1, s2, t1, t2;
map<string, int> mp;
while (cin >> s1 >> s2) {
mp[s1] = 1;
mp[s2] = 2;
ans[1] = s1, ans[2] = s2;
int n;
cin >> n;
cout << ans[1] << " " << ans[2] << endl;
for (int i = 0; i < n; i++) {
cin >> t1 >> t2;
if (mp[t1] == 1 || mp[t1] == 2)
ans[mp[t1]] = t2, mp[t2] = mp[t1], mp[t1] = 0;
else
ans[mp[t2]] = t1, mp[t1] = mp[t2], mp[t2] = 0;
cout << ans[1] << " " << ans[2] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> ws >> s2;
int t;
cin >> t;
vector<pair<string, string> > v;
for (int i = 0; i < t; i++) {
string a, b;
cin >> a >> ws >> b;
v.push_back(make_pair(a, b));
}
cout << s1 << " " << s2 << endl;
for (int i = 0; i < t; i++) {
if (s1 == v[i].first) {
s1 = v[i].second;
cout << s1 << " " << s2 << endl;
} else if (s2 == v[i].first) {
s2 = v[i].second;
cout << s1 << " " << s2 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, ta, tb;
cin >> a >> b;
int n;
scanf("%d", &n);
cout << a << ' ' << b << endl;
for (int i = 0; i < n; i++) {
cin >> ta >> tb;
if (a == ta)
a = tb;
else
b = tb;
cout << a << ' ' << b << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, i, j;
string s1, s2;
cin >> s1 >> s2;
scanf("%lld", &n);
string s3[n], s4[n];
for (i = 0; i < n; i++) {
cin >> s3[i] >> s4[i];
}
string tm1, tm2;
tm1 = s1;
tm2 = s2;
for (i = 0; i < n; i++) {
cout << tm1 << " " << tm2 << endl;
if (s3[i] == tm1) {
tm1 = s4[i];
} else if (s3[i] == tm2) {
tm2 = s4[i];
}
}
cout << tm1 << " " << tm2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void input();
void solve();
int main() {
string name1, name2;
set<string> S;
int N;
cin >> name1 >> name2;
S.insert(name1);
S.insert(name2);
cin >> N;
for (int i = 0; i < N; i++) {
for (set<string>::iterator it = S.begin(); it != S.end(); it++) {
cout << *it << " ";
}
cout << "\n";
cin >> name1 >> name2;
S.erase(name1);
S.insert(name2);
}
for (set<string>::iterator it = S.begin(); it != S.end(); it++) {
cout << *it << " ";
}
cout << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char a[100], b[100], c[100], d[100];
int la, lb, lc, ld, n;
bool equ(char* a, int la, char* b, int lb) {
if (la != lb) return false;
for (int i = 0; i < la; i++)
if (a[i] != b[i]) return false;
return true;
}
void modify(char* a, int* la, char* b, int* lb) {
for (int i = 0; i < (*lb); i++) a[i] = b[i];
*la = *lb;
}
void print(char* a, int la, char* b, int lb) {
for (int i = 0; i < la; i++) printf("%c", a[i]);
printf(" ");
for (int i = 0; i < lb; i++) printf("%c", b[i]);
printf("\n");
}
int main() {
scanf("%s%s", &a, &b);
la = 0;
while (a[la] != '\0') la++;
lb = 0;
while (b[lb] != '\0') lb++;
print(a, la, b, lb);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s%s", &c, &d);
lc = 0;
while (c[lc] != '\0') lc++;
ld = 0;
while (d[ld] != '\0') ld++;
if (equ(a, la, c, lc))
modify(a, &la, d, &ld);
else
modify(b, &lb, d, &ld);
print(a, la, b, lb);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string str[2];
cin >> str[0] >> str[1];
scanf("%d", &N);
cout << str[0] << " " << str[1] << endl;
for (int i = 0; i < N; ++i) {
string a, b;
cin >> a >> b;
if (str[0] == a)
str[0] = b;
else
str[1] = b;
cout << str[0] << " " << str[1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long int f, cnt, len, p, q, r, t, i, j, k, l, n, m, x, y, z, b, c, s;
string vic1, vic2, s1, s2;
cin >> vic1 >> vic2;
cin >> n;
cout << vic1 << " " << vic2 << "\n";
for (i = 0; i < n; i++) {
cin >> s1 >> s2;
if (s1 == vic1) {
vic1 = vic2;
vic2 = s2;
} else {
vic2 = vic1;
vic1 = s2;
}
cout << vic1 << " " << vic2 << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string a, b;
cin >> a >> b;
if (a > b) swap(a, b);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << a << " " << b << "\n";
string c, d;
cin >> c >> d;
if (c > d) swap(c, d);
if (a == c) {
a = d;
} else if (a == d) {
a = c;
} else if (b == c) {
b = d;
} else {
b = c;
}
}
cout << a << " " << b << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
set<string> S;
string s1, s2;
int n;
cin >> s1 >> s2;
cin >> n;
cout << s1 << " " << s2 << "\n";
S.insert(s1);
S.insert(s2);
for (int i = 1; i <= n; i++) {
cin >> s1 >> s2;
S.erase(s1);
S.insert(s2);
for (auto s : S) cout << s << " ";
cout << "\n";
}
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 x, y;
cin >> x >> y;
if (a == x) {
a = y;
} else {
b = y;
}
cout << a << " " << b << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
int i;
char name1[20], name2[20];
char tname1[20], tname2[20];
scanf("%s%s", name1, name2);
cin >> n;
for (i = 0; i < n; i++) {
printf("%s %s\n", name1, name2);
scanf("%s%s", tname1, tname2);
if (strcmp(name1, tname1) == 0)
strcpy(name1, tname2);
else
strcpy(name2, tname2);
}
printf("%s %s\n", name1, name2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s[10005], s1[10005], a, b;
cin >> a >> b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i] >> s1[i];
}
for (int i = 0; i < n; i++) {
cout << a << " " << b << endl;
if (a == s[i])
a = s1[i];
else
b = s1[i];
}
cout << a << " " << b << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[2];
cin >> s[0] >> s[1];
int n;
cin >> n;
for (int i = 0; i <= n; i++) {
if (i) {
string a, b;
cin >> a >> b;
if (a == s[0])
s[0] = b;
else if (a == s[1])
s[1] = b;
else if (b == s[0])
s[0] = a;
else
s[1] = a;
}
cout << s[0] << " " << s[1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long Inf = 1ll << 63 - 1;
string st1, st2, tp1, tp2;
int n;
int main() {
while (cin >> st1 >> st2) {
cin >> n;
cout << st1 << " " << st2 << endl;
while (n--) {
cin >> tp1 >> tp2;
if (tp1 == st1) {
st1 = tp2;
} else {
st2 = tp2;
}
cout << st1 << " " << st2 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
set<string> ss;
string strA, strB;
int n;
int main() {
cin >> strA >> strB;
ss.insert(strA);
ss.insert(strB);
cin >> n;
cout << strA << " " << strB << endl;
for (int i = 1; i <= n; i++) {
cin >> strA >> strB;
ss.erase(strA);
ss.insert(strB);
set<string>::iterator itor = ss.begin();
cout << *itor << " ";
itor++;
cout << *itor << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
cout << a << " " << b << "\n";
int n;
cin >> n;
while (n--) {
string x, y;
cin >> x >> y;
if (x == a) {
a = y;
} else {
b = y;
}
cout << a << " " << b << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s3, s4;
cin >> s1 >> s2;
int n;
cin >> n;
cout << s1 << " " << s2 << endl;
for (int i = 1; i <= n; i++) {
cin >> s3 >> s4;
if (s3 == s1)
s1 = s4;
else if (s3 == s2)
s2 = s4;
cout << s1 << " " << s2 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18;
const int INF = (int)1e9 + 7;
const int N = (int)1e5 + 1;
const double PI = 3.14159265359;
bool u[N + 5];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
string f, s;
f = s1;
s = s2;
cout << s1 << " " << s2 << endl;
for (int i = 1; i <= n; ++i) {
string s3, s4;
cin >> s3 >> s4;
if (s3 == s1) {
cout << s4 << " " << s2 << endl;
s1 = s4;
} else if (s3 == s2) {
cout << s4 << " " << s1 << endl;
s2 = s4;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string nameOne, nameTwo, tmpOne, tmpTwo;
cin >> nameOne >> nameTwo;
int n;
cin >> n;
cout << nameOne << " " << nameTwo << endl;
for (int i = 0; i < n; i++) {
cin >> tmpOne;
cin >> tmpTwo;
if (tmpOne == nameOne)
nameOne = tmpTwo;
else
nameTwo = tmpTwo;
cout << nameOne << " " << nameTwo << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
string a, b, c, d;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> a >> b >> n;
cout << a << ' ' << b << '\n';
for (int i = 0; i < n; ++i) {
cin >> c >> d;
if (a == c)
cout << d << ' ' << b, a = d;
else
cout << d << ' ' << a, b = d;
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
string a, b, c, d;
int n;
int main() {
while (cin >> a >> b) {
cout << a << " " << b << endl;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c >> d;
if (a == c)
a = d;
else
b = d;
cout << a << " " << b << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a1[1000000 + 10];
long long int b1[1000000 + 10];
long long int opp(long long int a) {
for (int i = 63; i >= 0; i--) {
if (a >> i & 1 == 1) {
return i;
break;
}
}
}
unsigned long long int p(int poo) {
long long int lop = 0;
while (poo != 0) {
lop += poo - 1;
poo--;
}
return lop;
}
long long int tav2(int p) {
if (p == 0) {
return 1;
} else if (p % 2 != 0) {
return (tav2(p - 1) * 2);
} else {
long long int l = tav2(p / 2);
return (l * l);
}
}
bool pol[1000];
int main() {
int t1, a, b, c, d = 0, z = 0;
string s, e;
cin >> s >> e;
cout << s << " " << e << endl;
cin >> a;
for (int i = 1; i <= a; i++) {
string f1, f2;
cin >> f1 >> f2;
if (s == f1) {
s = f2;
} else {
e = f2;
}
cout << s << " " << e << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rread(T& num) {
num = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar();
num *= f;
}
inline int getgcd(int x, int y) {
if (!x) return y;
return getgcd(y % x, x);
}
inline int power(int x, int k, int p) {
int res = 1;
for (; k; k >>= 1, x = (long long)x * x % p)
if (k & 1) res = (long long)res * x % p;
return res;
}
const double pi = acos(-1);
inline void judge() { freopen("input.txt", "r", stdin); }
int n;
string s[10];
int main() {
cin >> s[1] >> s[2];
rread(n);
cout << s[1] << " " << s[2] << endl;
for (int(i) = (1); (i) <= (n); (i)++) {
cin >> s[3] >> s[4];
for (int(j) = (3); (j) <= (4); (j)++) {
bool flag = 0;
for (int(k) = (1); (k) <= (2); (k)++)
if (s[j] == s[k]) {
flag = 1;
s[k] = s[7 - j];
break;
}
if (flag) break;
}
cout << s[1] << " " << s[2] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
pair<string, string> a;
int n;
string s1, s2;
int main() {
cin >> s1 >> s2 >> n;
a.first = s1;
a.second = s2;
for (int i = 1; i <= n; i++) {
cout << a.first << " " << a.second << endl;
cin >> s1 >> s2;
if (a.first == s1) {
a.first = s2;
} else {
a.second = s2;
}
}
cout << a.first << " " << a.second << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s, t;
cin >> s >> t;
int n;
cin >> n;
cout << s << " " << t << "\n";
string a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
if (s == a)
s = b;
else
t = b;
cout << s << " " << t << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
const int infty = numeric_limits<int>::max();
struct _ {
_() {
ios_base::Init i;
ios_base::sync_with_stdio(0);
cin.tie(0);
}
} _;
int main() {
string s, t;
cin >> s >> t;
int n;
cin >> n;
string a, b;
for (int i = 0; i < n; ++i) {
cout << t << ' ' << s << endl;
cin >> a >> b;
if (t == a)
t = b;
else
s = b;
}
cout << t << ' ' << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int MX = 2e6 + 8;
map<string, int> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string name1, name2;
cin >> name1 >> name2;
int n;
cin >> n;
vector<pair<string, string> > a;
a.push_back({name1, name2});
for (int i = 0; i < n; i++) {
string x, y;
cin >> x >> y;
a.push_back({x, y});
}
string cur1, cur2;
cur1 = a[0].first;
cur2 = a[0].second;
cout << cur1 << ' ' << cur2 << '\n';
for (int i = 1; i <= n; i++) {
string prev1 = a[i].first;
string prev2 = a[i].second;
if (prev1 == cur1) {
cur1 = cur2;
cur2 = prev2;
} else if (prev1 == cur2) {
cur2 = cur1;
cur1 = prev2;
} else if (prev2 == cur1) {
cur1 = cur2;
cur2 = prev1;
} else if (prev2 == cur2) {
cur2 = cur1;
cur1 = prev1;
}
cout << cur1 << ' ' << cur2 << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string first, second;
int n;
cin >> first >> second >> n;
cout << first << ' ' << second << endl;
for (int i = 0; i < n; i++) {
string m, r;
cin >> m >> r;
if (first == m)
first = r;
else
second = r;
cout << first << ' ' << second << endl;
}
}
|
#include <bits/stdc++.h>
const int N = 1005;
using namespace std;
string a, b, c, d;
int n;
int main() {
cin >> a >> b;
cin >> n;
cout << a << ' ' << b << endl;
for (int i = 0; i < n; i++) {
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() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string first, second;
cin >> first >> second;
int n;
cin >> n;
cout << first << " " << second << endl;
for (int i = 0; i < n; i++) {
string killed, replaceWith;
cin >> killed >> replaceWith;
if (killed == first) {
first = replaceWith;
} else {
second = replaceWith;
}
cout << first << " " << second << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long double safe_sqrt(long double x) { return sqrt(max((long double)0.0, x)); }
long long GI(long long& x) { return scanf("%lld", &x); }
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << (fixed) << setprecision(9);
string a, b;
while (cin >> a >> b) {
long long n;
cin >> n;
cout << a << ' ' << b << '\n';
for (long long i = (1), _b = (n); i <= _b; ++i) {
string x, y;
cin >> x >> y;
if (a == x)
a = y;
else
b = y;
cout << a << ' ' << b << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
cout << s1 << " " << s2 << "\n";
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
string s3, s4;
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
cout << s1 << " " << s2 << "\n";
} else {
s2 = s4;
cout << s1 << " " << s2 << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
setlocale(LC_CTYPE, "rus");
string s1, s2, s3, s4, s5[1002][2];
long int N, i, j;
cin >> s1 >> s2;
cin >> N;
s5[0][0] = s1;
s5[0][1] = s2;
for (i = 0; i < N; i++) {
cin >> s3 >> s4;
if (s3 == s1)
s1 = s4;
else if (s3 == s2)
s2 = s4;
s5[i + 1][0] = s1;
s5[i + 1][1] = s2;
}
for (i = 0; i < N + 1; i++) {
cout << s5[i][0] << ' ' << s5[i][1];
if (i != N) cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, m, n, p, q, r;
map<string, string> mp;
vector<pair<string, string> > v;
string x, y, a, b, d, s;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> x >> y;
cin >> n;
cout << x << " " << y << "\n";
mp[x] = x, mp[y] = y;
for (i = 0; i < n; i++) {
cin >> a >> b;
mp[a] = b;
mp[b] = b;
cout << mp[x] << " " << mp[y] << "\n";
x = mp[x], y = mp[y];
}
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "-O3"
const int N = (1e5 + 5);
int n;
string s1, s2;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> s1 >> s2 >> n;
cout << s1 << ' ' << s2 << '\n';
for (int i = 1; i <= n; i++) {
string x, y;
cin >> x >> y;
((x == s1) ? s1 : s2) = y;
cout << s1 << ' ' << s2 << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string name1, name2;
cin >> name1 >> name2;
int n;
cin >> n;
cout << name1 << " " << name2 << endl;
for (int i = 1; i <= n; i++) {
string temp1, temp2;
cin >> temp1 >> temp2;
if (temp1 == name1)
name1 = temp2;
else
name2 = temp2;
cout << name1 << " " << name2 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, d;
map<string, int> a;
cin >> s;
cin >> d;
a[s]++;
a[d]++;
int n;
cin >> n;
cout << s;
cout << " ";
cout << d;
cout << "\n";
while (n--) {
cin >> s;
cin >> d;
a[s]++;
a[d]++;
a[s] = 0;
map<string, int>::iterator itr;
for (itr = a.begin(); itr != a.end(); itr++) {
if (itr->second == 1) {
cout << itr->first;
cout << " ";
}
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string x[1001], y[1001];
string a, b, s;
cin >> a >> b;
x[0] = a;
y[0] = b;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
if (a == x[i - 1])
x[i] = b, y[i] = y[i - 1];
else if (a == y[i - 1])
x[i] = x[i - 1], y[i] = b;
}
for (int i = 0; i <= n; i++) cout << x[i] << " " << y[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string v1, v2;
vector<string> result;
cin >> v1 >> v2;
result.push_back(v1);
result.push_back(v2);
int n, i;
cin >> n;
for (i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
if (a == v1) {
result.push_back(v2);
v1 = v2;
} else {
result.push_back(v1);
}
result.push_back(b);
v2 = b;
}
for (i = 0; i < result.size(); i += 2) {
cout << result[i] << " " << result[i + 1] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X abs(const X& a) {
return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
const int INF = 1e9 + 1;
const long long INF1 = 1e18 + 1;
const int size = 1e5 + 2;
const double eps = 0.0001;
const long double PI = 3.1415926535897932384626433832795;
const int MOD = 1000000007;
const int INF2 = 0x3f3f3f3f;
const long long INFF = 1LL << 60;
void solution();
void include_file();
long long bin_search(long long left, long long right);
int main() {
ios_base::sync_with_stdio(false);
solution();
return 0;
}
void include_file() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
vector<vector<int> > g;
int was[100];
void dfs(int v) {
if (was[v]) return;
was[v] = 1;
for (int i = 0; i < g[v].size(); ++i) {
dfs(g[v][i]);
}
}
int bfs(int s, int toto) {
queue<int> q;
vector<bool> used(1001);
vector<int> d(1001), p(1001);
q.push(s);
used[s] = true;
p[s] = 1;
d[s] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (size_t i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (!used[to]) {
used[to] = true;
q.push(to);
d[to] = d[v] + 1;
p[to] = v;
}
}
}
return d[toto];
}
void yes() { cout << "YES"; }
void no() { cout << "NO"; }
namespace bits {
template <typename X>
inline X MAX(const X& a, const X& b) {
return b & ((a - b) >> 31) | a & (~(a - b) >> 31);
}
template <typename X>
inline X MIN(const X& a, const X& b) {
return a & ((a - b) >> 31) | b & (~(a - b) >> 31);
}
bool check2(const long long n) { return n > 0 && (n & (n - 1)); }
long long ostatok2(const long long n, const long long m) { return m & (n - 1); }
template <typename X>
void SWAP(X& a, X& b) {
a ^= b;
b ^= a;
a ^= b;
}
} // namespace bits
void solution() {
string s1, s2;
int n;
string s[1000], t[1000];
cin >> s1 >> s2 >> n;
for (int i = 0; i < n; ++i) cin >> s[i] >> t[i];
cout << s1 << " " << s2 << endl;
for (int i = 0; i < n; ++i) {
if (s[i] == s1)
s1 = t[i];
else
s2 = t[i];
cout << s1 << " " << s2 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string victim1, victim2, killed, replacing;
cin >> victim1 >> victim2;
cin >> n;
cout << victim1 << ' ' << victim2 << '\n';
while (n--) {
cin >> killed >> replacing;
if (killed == victim1) {
victim1 = replacing;
} else {
victim2 = replacing;
}
cout << victim1 << ' ' << victim2 << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e3 + 10;
int n;
string s, t;
int main() {
cin >> s >> t;
cout << s << " " << t << endl;
cin >> n;
for (int i = 0; i < n; i++) {
string del, ne;
cin >> del >> ne;
if (del == t)
t = ne;
else
s = ne;
cout << s << " " << t << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
string a[1001][2], b[1001][2];
int main() {
cin >> a[0][0] >> a[0][1];
b[0][0] = a[0][0];
b[0][1] = a[0][1];
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i][0] >> a[i][1];
if (a[i][0] == b[i - 1][0]) {
b[i][0] = a[i][1];
b[i][1] = b[i - 1][1];
} else {
b[i][0] = b[i - 1][0];
b[i][1] = a[i][1];
}
}
for (int i = 0; i <= n; i++) cout << b[i][0] << " " << b[i][1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
vector<pair<string, string> > v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i].first >> v[i].second;
}
v[0] = {s1, s2};
cout << s1 << " " << s2 << endl;
for (int i = 1; i <= n; i++) {
cout << v[i].second << " ";
if (v[i - 1].first != v[i].first) {
cout << v[i - 1].first << endl;
v[i].first = v[i - 1].first;
} else {
cout << v[i - 1].second << endl;
v[i].first = v[i - 1].second;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s[1000000];
int main() {
string s1, s2, s3, s4;
cin >> s1 >> s2;
int n;
cin >> n;
cout << s1 << " " << s2 << endl;
while (n--) {
cin >> s3 >> s4;
if (s3 == s1) {
cout << s4 << " " << s2 << endl;
s1 = s4;
s2 = s2;
continue;
} else if (s3 == s2) {
cout << s1 << " " << s4 << endl;
s1 = s1;
s2 = s4;
continue;
} else if (s4 == s1) {
cout << s3 << " " << s2 << endl;
s1 = s3;
s2 = s2;
continue;
} else if (s4 == s2) {
cout << s1 << " " << s3 << endl;
s1 = s1;
s2 = s3;
continue;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, z;
string s1, s2;
cin >> s1 >> s2;
cin >> n;
string s3, s4;
cout << s1 << ' ' << s2 << endl;
for (int i = 0; i < n; i++) {
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
cout << s1 << ' ' << s2 << endl;
} else {
s2 = s4;
cout << s1 << ' ' << s2 << endl;
}
}
}
|
#include <bits/stdc++.h>
int main() {
std::set<std::string> a;
std::string x, y;
std::cin >> x >> y;
a.insert(x);
a.insert(y);
std::cout << (*a.begin()) << " " << (*(++a.begin())) << std::endl;
int n;
std::cin >> n;
while (n--) {
std::cin >> x >> y;
a.erase(x);
a.insert(y);
std::cout << (*a.begin()) << " " << (*(++a.begin())) << std::endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int maxn = 1e5 + 10;
string s1, s2, s3, s4;
string ans1[1005], ans2[1005];
int main() {
cin >> s1 >> s2;
int n = read();
ans1[0] = s1, ans2[0] = s2;
for (int i = 1; i <= n; i++) {
cin >> s3 >> s4;
if (s3 == ans1[i - 1]) {
ans1[i] = ans2[i - 1];
ans2[i] = s4;
} else {
ans1[i] = ans1[i - 1];
ans2[i] = s4;
}
}
for (int i = 0; i <= n; i++) cout << ans1[i] << " " << ans2[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
long long n;
scanf("%lli", &n);
cout << a << " " << b << endl;
for (long long i = 0; i < n; i++) {
string c, d;
cin >> c >> d;
if (c == a)
a = d;
else if (c == b)
b = d;
cout << a << " " << b << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int n;
cin >> a >> b;
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 if (c == b)
b = d;
cout << a << " " << b << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string str1, str2, ans1, ans2;
cin >> str1 >> str2;
ans1 = str1;
ans2 = str2;
cout << ans1 << " " << ans2 << endl;
cin >> n;
while (n--) {
cin >> str1 >> str2;
if (str1 == ans1) {
ans1 = str2;
} else
ans2 = str2;
cout << ans1 << " " << ans2 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
set<string> ss;
string str;
int n;
int main() {
cin >> str;
ss.insert(str);
cin >> str;
ss.insert(str);
cin >> n;
for (set<string>::iterator itor = ss.begin(); itor != ss.end(); itor++)
cout << *itor << " ";
cout << endl;
for (int i = 1; i <= n; i++) {
cin >> str;
ss.erase(ss.find(str));
cin >> str;
ss.insert(str);
for (set<string>::iterator itor = ss.begin(); itor != ss.end(); itor++)
cout << *itor << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
string a, b;
cin >> a >> b;
cout << a << " " << b << endl;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s == a)
cin >> a;
else
cin >> b;
cout << a << " " << b << endl;
}
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > v;
string q, w, e, r, t, y, u;
long long int a, s, d, f, g, h;
int main() {
cin >> e >> r >> a;
for (int i = 0; i < a; i++) cin >> q >> w, v.push_back(make_pair(q, w));
cout << e << " " << r << endl;
for (int i = 0; i < a; i++) {
if (v[i].first == e) e = v[i].second;
if (v[i].first == r) r = v[i].second;
cout << e << " " << r << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string st1, st2;
cin >> st1 >> st2;
int a;
cin >> a;
string n[a], m[a];
for (int i = 0; i < a; i++) {
cin >> n[i] >> m[i];
}
cout << st1 << " " << st2 << endl;
for (int i = 0; i < a; i++) {
if (n[i] == st1) {
cout << st2 << " " << m[i] << endl;
st1 = m[i];
} else {
cout << st1 << " " << m[i] << endl;
st2 = m[i];
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> read_int_array(int n) {
vector<int> arr;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
arr.push_back(temp);
}
return arr;
}
vector<long long int> read_llint_array(int n) {
vector<long long int> arr;
for (int i = 0; i < n; i++) {
long long int temp;
cin >> temp;
arr.push_back(temp);
}
return arr;
}
int main() {
string n1, n2;
cin >> n1 >> n2;
int n;
cin >> n;
cout << n1 << " " << n2 << endl;
for (int i = 0; i < n; i++) {
string killed, repl;
cin >> killed >> repl;
if (n1 == killed) {
n1 = repl;
} else {
n2 = repl;
}
cout << n1 << " " << n2 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, k, j, l, m = 1, c = 0, o, x;
string f, s, dead, newy, z;
cin >> f >> s;
cin >> n;
deque<string> vics;
deque<string> order;
vics.push_front(f);
vics.push_front(s);
order.push_front(f);
order.push_front(s);
for (i = 0; i < n; i++) {
cin >> dead >> newy;
if (vics.front() == dead) {
vics.pop_front();
vics.push_front(newy);
} else {
vics.pop_back();
vics.push_back(newy);
}
order.push_front(vics.front());
order.push_front(vics.back());
}
while (order.size() != 0) {
cout << order.back() << " ";
order.pop_back();
cout << order.back() << endl;
order.pop_back();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<string, string> p[1002], p1;
cin >> p1.first >> p1.second;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
cout << p1.first << " " << p1.second << endl;
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
if (p[i].first == p1.first) {
cout << p[i].second << " " << p1.second << endl;
p1.first = p[i].second;
break;
} else if (p[i].first == p1.second) {
cout << p1.first << " " << p[i].second << endl;
p1.second = p[i].second;
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string arr[1001][2], ne[1001][2], l;
int i;
int n;
cin >> arr[0][0] >> arr[0][1];
cin >> n;
for (i = 1; i <= n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
ne[0][0] = arr[0][0];
ne[0][1] = arr[0][1];
for (i = 1; i <= n; i++) {
if (arr[i][0] != ne[i - 1][0])
l = ne[i - 1][0];
else if (arr[i][0] != ne[i - 1][1])
l = ne[i - 1][1];
ne[i][0] = l;
ne[i][1] = arr[i][1];
}
for (i = 0; i <= n; i++) cout << ne[i][0] << " " << ne[i][1] << endl;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[1001], ss[1001];
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>
const int INF = 10e9 + 7;
using namespace std;
int main() {
string s1 = "", s2 = "", s3 = "", s4 = "", s;
cin >> s1 >> s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << s1 << " " << s2 << endl;
cin >> s3 >> s4;
if (s3 == s1) {
s1 = s4;
continue;
}
if (s3 == s2) {
s2 = s4;
continue;
}
if (s4 == s1) {
s1 = s3;
continue;
}
if (s4 == s2) {
s2 = s3;
continue;
}
}
cout << s1 << " " << s2 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int days;
string currentA, currentB, choose, rep;
int main() {
cin >> currentA >> currentB;
cout << currentA << " " << currentB << endl;
cin >> days;
for (int i = 0; i < days; i++) {
cin >> choose >> rep;
if (choose == currentA) {
currentA = rep;
} else {
currentB = rep;
}
cout << currentA << " " << currentB << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string a, s, b, c;
cin >> a >> s;
cin >> n;
cout << a << " " << s << endl;
while (n--) {
cin >> b >> c;
if (b == a)
a = c;
else if (b == s)
s = c;
cout << a << " " << s << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
char str_1[15];
char str_2[15];
char str_3[15];
char str_4[15];
int main() {
int n;
scanf("%s%s", str_1, str_2);
scanf("%d", &n);
printf("%s %s\n", str_1, str_2);
for (int i = 0; i < n; i++) {
getchar();
scanf("%s%s", str_3, str_4);
if (strcmp(str_1, str_3) == 0) {
strcpy(str_1, str_4);
} else {
for (int i = 0; i < strlen(str_4); i++) {
strcpy(str_2, str_4);
}
}
printf("%s %s\n", str_1, str_2);
memset(str_3, 0, sizeof(str_3));
memset(str_4, 0, sizeof(str_4));
memset(str_3, 0, sizeof(str_1));
memset(str_4, 0, sizeof(str_2));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, t1, s2, t2;
int n;
cin >> s1 >> s2 >> n;
cout << s1 << " " << s2 << "\n";
while (n--) {
cin >> t1 >> t2;
if (t1 == s1)
s1 = t2;
else
s2 = t2;
cout << s1 << " " << s2 << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b, c, d;
int main() {
int n;
cin >> a >> b;
cout << a << ' ' << b << endl;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c >> d;
if (c == a)
cout << d << ' ' << b << endl, a = d;
else if (c == b)
cout << a << ' ' << d << endl, b = d;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j;
char s[1000][20], s11[1000][20], s1[100], s2[100];
while (~scanf("%s%s", s1, s2)) {
scanf("%d", &n);
getchar();
for (i = 0; i <= n; i++) {
if (i == 0) {
strcpy(s[i], s1);
strcpy(s11[i], s2);
printf("%s %s\n", s1, s2);
} else
scanf("%s%s", s[i], s11[i]);
if (strcmp(s[i], s[i - 1]) == 0) {
printf("%s %s\n", s11[i], s11[i - 1]);
strcpy(s[i], s11[i]);
strcpy(s11[i], s11[i - 1]);
}
if (strcmp(s[i], s11[i - 1]) == 0) {
printf("%s %s\n", s[i - 1], s11[i]);
strcpy(s[i], s[i - 1]);
strcpy(s11[i], s11[i]);
}
}
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.