Junior — Senior
English alphabet iteration with symbol replacement according to specified rules
livecode
Task condition
It is necessary to implement a program in Go that outputs the sequence of English alphabet characters from 'A' to 'Z' with the following transformations:
- Each character is printed on a separate line.
- Every third character is replaced by its position number in the alphabet (for example, the letter 'C' is replaced with the number 3).
- Every fifth character is replaced with the corresponding Russian letter with the same position (for example, the fifth letter 'E' is displayed as 'Д', since in the Russian alphabet 'А'-'Д' occupy positions 1-4).
- The fifteenth character ('O') is displayed as the string "Привет".
package main
import "fmt"
func main(){
for i := 0; i < 26; i++ {
position := i + 1
char := rune('A' + i)
if position == 15 {
fmt.Println("Привет")
} else if position%3 == 0 {
fmt.Println(position)
} else if position%5 == 0 {
// Map the position to the corresponding Russian letter
russianLetters := "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"
if position <= len(russianLetters) {
fmt.Println(string(russianLetters[position-1]))
} else {
fmt.Println(string(char))
}
} else {
fmt.Println(string(char))
}
}
}