MetaOA #22
Replace Every Nth Consonant
Estimated EasyJudge-ready
Topics (AI-labelled)Strings
Count the consonants among the English letters from left to right, and replace every n-th consonant with the next consonant in alphabetical order, preserving case; z/Z wraps around to b/B. The consonant order is bcdfghjklmnpqrstvwxyz. Vowels, spaces, digits, and punctuation are not counted and are left unchanged.
Input
This site's input: the first line contains n (1..100000), and the second line is printable ASCII text of length 0..100000, which may contain leading, trailing, and consecutive spaces.
Output
Output the complete text after replacement, keeping all spaces and case, and end it with a single newline.
Example 1
Input:
3
CodeSignal
Output:
CodeTignam
Example 2
Input:
1
z Z!
Output:
b B!
Example 3
Input:
2
a b
Output:
a b
Example notes
Example 1: the consonants in order are C, d, S, g, n, l; the 3rd, S, becomes T, and the 6th, l, becomes m, giving CodeTignam.
Example 2: every consonant is replaced; z wraps to b and Z wraps to B, so the output is b B!.
Example 3: there is only one consonant, b, so the 2nd is never reached, and the whole line, including all spaces, is output unchanged.
Editorial
Loading solution…