-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCensored-String.txt
67 lines (56 loc) · 1.35 KB
/
Censored-String.txt
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
# Censored Strings Challenge
https://edabit.com/challenge/Wv9ZeXyC32EMfRWGB My solution in various languages to this problem.
## C++:
std::string uncensor(std::string str, std::string vowels) {
std::string res = "";
int cur = 0;
for(int i = 0; i < str.size(); i++) {
if(str[i] == '*') {
res += vowels[cur];
cur++;
}
else {
res+= str[i];
}
}
return res;
}
## Python:
def uncensor(txt, vowels):
listTxt = list(txt)
listVowels = list(vowels)
vowelsCounter = 0
for x in range(len(listTxt)):
if listTxt[x] == "*":
listTxt[x] = listVowels[vowelsCounter]
vowelsCounter += 1
result = ""
for x in listTxt:
result += x
return result
## JavaScript:
function uncensor(str, vowels) {
var newString = ''
var vowelsCounter = 0
for(var i = 0; i < str.length; i ++){
if(str.charAt(i)==='*'){
newString += vowels[vowelsCounter]
vowelsCounter++
}
else{
newString += str.charAt(i)
}
}
return newString
}
## Java:
public class Challenge {
public static String uncensor(String str, String vowels) {
String uncensored = "";
int vowelCounter = 0;
for (int i = 0; i < str.length(); i++) {
uncensored += (str.charAt(i) != '*' ? str.charAt(i) : vowels.charAt(vowelCounter++));
}
return uncensored;
}
}