Tracks
/
C++
C++
/
Exercises
/
Pig Latin
Pig Latin

Pig Latin

Medium

Introduction

Your parents have challenged you and your sibling to a game of two-on-two basketball. Confident they'll win, they let you score the first couple of points, but then start taking over the game. Needing a little boost, you start speaking in Pig Latin, which is a made-up children's language that's difficult for non-children to understand. This will give you the edge to prevail over your parents!

Instructions

Your task is to translate text from English to Pig Latin using the following rules:

  • Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word (e.g. "apple" -> "appleay"). Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay").
  • Rule 2: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word (e.g. "pig" -> "igpay"). Consonant sounds can be made up of multiple consonants, such as the "ch" in "chair" or "st" in "stand" (e.g. "chair" -> "airchay").
  • Rule 3: If a word starts with a consonant sound followed by "qu", move them to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay").
  • Rule 4: If a word contains a "y" after a consonant cluster or as the second letter in a two letter word it makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay").
Edit via GitHub The link opens in a new window or tab
C++ Exercism

Ready to start Pig Latin?

Sign up to Exercism to learn and master C++ with 16 concepts, 94 exercises, and real human mentoring, all for free.