PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000260. Dịch chuyển chữ cái II (Shifting Letters II)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dịch chuyển chữ cái II (Shifting Letters II)
Shifting Letters II
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a lowercase string of length , indexed from 0, each operation shifts every character in by one alphabet position, forward for and backward for , wrapping between a and z. Print the final string.
Input
First line: . Second line: . Next lines: .
Output
Print the resulting string.
Subtasks
- Subtask 1 (20 points): ; ; ; ; S consists of N lowercase letters a–z.
- Subtask 2 (30 points): ; ; ; ; S consists of N lowercase letters a–z; .
- Subtask 3 (50 points): ; ; ; ; S consists of N lowercase letters a–z.
Example 1
Input
3 3
abc
0 1 0
1 2 1
0 2 1
Output
ace
Explanation
abc → zac → zbd → ace.
Example 2
Input
4 2
dztz
0 0 0
1 1 1
Output
catz
Explanation
Shift d backward to c, then z forward to a.