#K61897. Capitalize Every k-th Character
Capitalize Every k-th Character
Capitalize Every k-th Character
Given a string s
consisting of lowercase alphabetical characters and an integer k
, output a new string where every k-th character (based on 1-indexing) is converted to uppercase. For instance, if s = "abcdefg"
and k = 2
, the output should be aBcDeFg
because the 2nd, 4th, 6th, ... characters are capitalized.
Note: If k
is greater than the length of the string, then output the original string unchanged.
The relation can be expressed using the formula: \( \text{if } (i+1) \mod k = 0 \text{ then } s[i] \to \text{upper}(s[i]) \), where \( i \) starts from 0.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains a string
s
composed solely of lowercase English letters. - The second line contains an integer
k
indicating the interval at which characters should be capitalized.
outputFormat
Output the modified string after capitalizing every k-th character (using 1-indexing) to standard output.
## sampleabcdefg
2
aBcDeFg