It was a dark and stormy night, and John was feeling anxious as he approached the mysterious combina…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
String ss = scan.nextLine();
char[] arr = ss.toCharArray();
for (int i = 0; i < arr.length; i++) {
if (arr[i] == ' ') {
System.out.print(arr[i]);
} else {
int num = (int) arr[i];
if (num - n < 97) {
int re = (num - n) + 26;
System.out.print((char)re);
} else {
System.out.print((char) (num-2));
}
}
}
System.out.println();
}
}
what’s wrong with that code
it shows wrong ans in 2nd testcase
What’s wrong in this Code??
n = int(input())
element_of_n = list(map(str, input().split()))
new_element = []
for i in range(len(element_of_n)):
tem = []
for j in range(len(element_of_n[i])):
if element_of_n[i][j] == ‘a’:
tem.append(‘y’)
elif element_of_n[i][j] == ‘b’:
tem.append(‘z’)
else:
o_t = ord(element_of_n[i][j])
tem.append(chr(o_t-2))
new_element.append(‘’.join(tem))
print(*new_element)
The problem is, in your solution you are predicting that the key N will always be 2. What if the key changes? Will your solution be working then? Try fixing this issue and you can get an AC.
#python 3.8
A = input()
B = input()
letter = "abcdefghijklmnopqrstuvwxyz"
new=""
a = 0
b = len(B)-1
while a <= b:
if B[a] == " ":
new += " "
else:
g = letter.index(B[a])
g -= 2
if g < 0:
g += 26
new += letter[g]
a += 1
print(new)