-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbob.cpp
62 lines (56 loc) · 1.37 KB
/
bob.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
map<char,char>mp,mp1;
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
char a,b;
cin>>a>>b;
a=toupper(a);
b=toupper(b);
if(mp.find(a)==mp.end() && mp.find(b)==mp.end())
{
mp[a]=b;
mp[b]=a;
}
else if(mp.find(a)!=mp.end() && mp.find(b)==mp.end())
{
mp[b]=mp[a];
mp[a]=b;
}
else if(mp.find(a)==mp.end() && mp.find(b)!=mp.end())
{
mp[a]=mp[b];
mp[b]=a;
}
else if(mp.find(a)!=mp.end() && mp.find(b)!=mp.end())
{ char temp=mp[b];
mp[b]=mp[a];
mp[a]=temp;
}
else{}
}
map<char,char>::iterator it;
for(it=mp.begin();it!=mp.end();it++)
{
mp1[it->second]=it->first;
}
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{ char ch=tolower(s[i]);
if(mp1.find(ch)!=mp1.end())
{ //cout<<90;
if(s[i]>='a' && s[i]<='z')
s[i]=mp1[ch];
else
s[i]=mp1[ch]-32;
}
}
cout<<s<<"\n";
//mp.clear();
return 0;
}