Codeforces A Serial Killer
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 10003;
struct printf
{
void ek(int n){cout << n << "\n";}
void dui(int x , int y) { cout << x << " " << y << "\n"; }
void tin(int x , int y , int z) { cout << x << " " << y << " " << z << "\n"; }
}tp;
struct sieve
{
int prm[high], plen=0;
bitset<high>bs;
void get_prime()
{
LL i , j;
bs.set();
bs[0]=bs[1]=0;
for(i=2; i<=high; i++)
{
if(bs[i])
{
prm[plen++] = i;
for(j=i*i; j<=high; j+=i) bs[j] = 0;
}
}
}
void pprm(){ for(int i=0; i<100; i++) cout << prm[i] << "; "; }
}prime;
pair<string, string>pstring[high];
int main()
{
fast;
int days=0;
mpsi mp;
vs v;
int i=0 , len=0;
string name1 , name2 , tmp;
while(cin >> name1 >> name2)
{
mp.clear();
v.clear();
cin >> days;
cout << name1 << " " << name2 << "\n";
mp[name1] = 1;
mp[name2] = 1;
v.push_back(name1);
v.push_back(name2);
len=v.size();
while(days--)
{
cin >> name1 >> name2;
mp[name1] = 0;
len = v.size();
v.push_back(name2);
for(i=0; i<len; i++)
{
if(mp[v[i]])
{
cout << v[i] << " ";
}
}
cout << name2 << "\n";
mp[name2] = 1;
//v.push_back(name2);
}
}
return 0;
}
===================== Fastest Solution ====================================
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 100;
int main()
{
fast;
int days;
string name1 , name2 , c , d;
while(cin >> name1 >> name2)
{
cin >> days;
cout << name1 << " " << name2 << "\n";
while(days--)
{
cin >> c >> d;
if(c == name1) name1 = name2 , name2 = d;
else name2 = d;
cout << name1 << " " << name2 << "\n";
}
}
return 0;
}
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 10003;
struct printf
{
void ek(int n){cout << n << "\n";}
void dui(int x , int y) { cout << x << " " << y << "\n"; }
void tin(int x , int y , int z) { cout << x << " " << y << " " << z << "\n"; }
}tp;
struct sieve
{
int prm[high], plen=0;
bitset<high>bs;
void get_prime()
{
LL i , j;
bs.set();
bs[0]=bs[1]=0;
for(i=2; i<=high; i++)
{
if(bs[i])
{
prm[plen++] = i;
for(j=i*i; j<=high; j+=i) bs[j] = 0;
}
}
}
void pprm(){ for(int i=0; i<100; i++) cout << prm[i] << "; "; }
}prime;
pair<string, string>pstring[high];
int main()
{
fast;
int days=0;
mpsi mp;
vs v;
int i=0 , len=0;
string name1 , name2 , tmp;
while(cin >> name1 >> name2)
{
mp.clear();
v.clear();
cin >> days;
cout << name1 << " " << name2 << "\n";
mp[name1] = 1;
mp[name2] = 1;
v.push_back(name1);
v.push_back(name2);
len=v.size();
while(days--)
{
cin >> name1 >> name2;
mp[name1] = 0;
len = v.size();
v.push_back(name2);
for(i=0; i<len; i++)
{
if(mp[v[i]])
{
cout << v[i] << " ";
}
}
cout << name2 << "\n";
mp[name2] = 1;
//v.push_back(name2);
}
}
return 0;
}
===================== Fastest Solution ====================================
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 100;
int main()
{
fast;
int days;
string name1 , name2 , c , d;
while(cin >> name1 >> name2)
{
cin >> days;
cout << name1 << " " << name2 << "\n";
while(days--)
{
cin >> c >> d;
if(c == name1) name1 = name2 , name2 = d;
else name2 = d;
cout << name1 << " " << name2 << "\n";
}
}
return 0;
}
Comments
Post a Comment