public String encryptThis(String str) {
String result = "";
String[] split = str.split(" ");
for (int j = 0; j < split.length; j++) {
char[] chars = split[j].toCharArray();
String res = "";
for (int i = 0; i < chars.length; i++) {
if (i == 0) {
res += Integer.valueOf(chars[i]);
} else if (i == 1) {
res += String.valueOf(chars[i + 1]);
} else if (i == 2) {
res += String.valueOf(chars[i - 1]);
} else {
res += String.valueOf(chars[i]);
}
}
result += res + " ";
}
return result.trim();
}
def encrypt_this(text:str):
li=text.split()
for i in range(len(li)):
li2=list(li[i])
if len(li2)>=3:
tmp=li2[1]
li2[1]=li2[-1]
li2[-1]=tmp
li2[0]=str(ord(li2[0]))
li[i]=''.join(li2)
return ' '.join(li)
def encrypt_this(text: str) -> str:
data = text.split(" ")
data2 = []
for t in data:
if len(t) > 2:
a = t[1]
b = t[-1]
t1 = t[0] + b + t[2:-1] + a
else:
t1 = t
t2 = str(ord(t1[0])) + t1[1:]
data2.append(t2)
return ' '.join(data2)
assert encrypt_this("Hello") == "72olle"
assert encrypt_this("A wise old owl lived in an oak") == "65 119esi 111dl 111lw 108dvei 105n 97n 111ka"
assert encrypt_this("The more he saw the less he spoke") == "84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp"