-
Notifications
You must be signed in to change notification settings - Fork 0
/
96_C.cpp
96 lines (84 loc) · 1.35 KB
/
96_C.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
string toLower(string& t)
{
string ret;
for(int i=0;i<t.length();i++){
ret+=tolower(t[i]);
}
return ret;
}
char convert(char ans, bool isUpper, char c)
{
char cand;
if(isUpper)
cand = 'A';
else
cand = 'a';
while(tolower(cand) == tolower(c))
{
cand++;
}
return cand;
}
char process(char ans, char c)
{
if(tolower(ans) != tolower(c))
{
return islower(ans) ? tolower(c) : toupper(c);
}
return convert(ans, isupper(ans), c);
}
void mark(vector<bool>&b,int finder ,int l)
{
for(int i=finder;i<finder+l;i++){
b[i] = 1;
}
}
int main()
{
int n;
cin>>n;
vector<string>a(n);
vector<string>l(n);
for(int i=0;i<n;i++){
cin>>a[i];
l[i] = toLower(a[i]);
}
string s;
cin>>s;
string LC;
LC = toLower(s);
char c;
cin>>c;
sort(l.begin(),l.end());
sort(a.begin(),a.end());
//for(int i=0;i<a.size();i++){
// cout<<l[i]<<" "<<a[i]<<endl;
// }
int index = 0;
string ans = s;
vector<bool>b((int)ans.length());
for(int i=0;i<l.size();i++){
int index = 0;
while(true)
{
int finder = LC.find(l[i],index++);
if(finder == string::npos)
break;
mark(b,finder,(int)l[i].length());
}
}
for(int i=0;i<(int)b.size();i++){
if(b[i])
{
ans[i] = process(ans[i],c);
}
}
cout<<ans<<endl;
return 0;
}