We need to decode a sentence. The encoding: for each word, after each vowel (a, e, i, o, u) we put the letter 'z' followed by that very vowel. So the pattern: vowel -> vowel + 'z' + vowel? Actually "manipulates each word in a sentence by putting the letter 'z' after each vowel, followed by that very vowel." That means original vowel becomes vowel + 'z' + same vowel? Wait the examples: "belina" -> "bezelizinaza". Let's check original: b e l i n a. Vowels: e, i, a. Encoding: for each vowel, we put 'z' after the vowel, then that same vowel again. So the pattern: vowel => vowel + 'z' + vowel. So original vowel becomes a triplet: vowel, z, same vowel. So "e" becomes "eze". "i" becomes "izi". "a" becomes "aza". Then the word becomes: b + (e->eze) + l + (i->izi) + n + (a->aza) => "bezelizinaza". Yes.
Second example: "zazhiba" -> "zazazhizibaza". Let's check: original: z a z h i b a. Vowels: a, i, a. Each becomes a+z+a => aza, i -> izi, a -> aza. So encode: z + (a->aza) + z + h + (i->izi) + b + (a->aza) => "zazazhizibaza". Yes.
Thus decoding: given a coded string, we need to reverse the transformation. For each occurrence of a vowel followed by "z" and the same vowel, we should collapse it to just the vowel. But careful: there could be occurrences of "aza", "eze", "izi", "ozo", "uzu" that are not part of the encoding but might naturally occur? The input is the encoded sentence, so any such patterns originally came from encoding only. But there might be overlapping? Actually encoding inserts explicitly these patterns after each vowel. So the original word didn't have such triple patterns because the original word only had vowels singly. So in the encoded string, every vowel that was originally present has been replaced by vowel + 'z' + vowel, but there could be 'z' characters that are part of original word that are not part of these patterns? Possibly yes, because original can have consonants including 'z'. For example "zazhiba" contains 'z' consonant before the vowel. That 'z' remains unchanged, but encoding added extra 'z's and vowels. So decoding must identify sequences where a vowel is followed by 'z' followed by the same vowel, and replace them with just the vowel. But be careful: these sequences could appear due to combination of original letters? Consider if original had "aza" as three letters, that would be: 'a' (vowel) then 'z' (consonant) then 'a' (vowel). In encoding, each vowel gets expanded, so original 'a' becomes "aza", the 'z' stays 'z', then next 'a' becomes "aza". So the encoded version would be: (a->aza) + z + (a->aza) => "aza" + "z" + "aza" = "azazaza". That contains "aza" repeated. But there is a pattern "aza" that appears as part of the expansion. However decoding we need to know which "aza" correspond to original vowel and which to the inserted patterns? The rule: we need to reverse the encoding: for each vowel, it was replaced by vowel+z+vowel. So in the encoded string, every occurrence of a vowel that is part of an encoded pattern is actually the first vowel of the triplet. So we need to scan and whenever we see a vowel, if it is followed by 'z' and then the same vowel, we should remove the 'z' and the second vowel, i.e., keep only the first vowel. But is that always safe? Let's test with "azazaza". Decoding: start at position 0: 'a', look ahead: next char 'z', next char 'a'? Yes, it's "aza". So we collapse to 'a', and skip the 'z' and the following 'a'. Then we continue from after that? After collapsing, we consumed three characters and output 'a'. Now the string continues from index 3? Let's simulate: encoded = "a z a z a z a"? Actually "azazaza" is 7 letters? Wait "azazaza" length 7? Let's write: indices: 0:a,1:z,2:a,3:z,4:a,5:z,6:a. So we start at index0: a then z then a => pattern, collapse -> output 'a', move to index3 (after consumed). Index3 is 'z'. Now we look: is it a vowel? No, so output 'z' and move to index4. Index4: 'a', check pattern: next is index5='z', index6='a' => yes "aza". Collapse to 'a', move to index7 (end). So output: 'a' + 'z' + 'a' = "aza". That matches original? Original we said had "aza"? Actually original word: we hypothesized original was "aza"? But original had 'a' (vowel) then 'z' then 'a'. That would be "aza". In encoding, each vowel expands: first 'a' -> "aza", 'z' remains, second 'a' -> "aza", resulting in "aza"+"z"+"aza" = "azazaza". So decoding "azazaza" yields "aza". That's correct.
Now consider if original had "zaz" (consonant 'z', vowel 'a', consonant 'z')? Actually 'a' is vowel, so it gets expanded: z + (a->aza) + z = "zazaz"? Wait compute: original: z a z => encode: z + (a->aza) + z = "zazaz". So encoded is "zazaz". Decoding: start at index0: 'z' (consonant) -> output 'z', index1: 'a' then next 'z' then next 'a'? Check: index1='a', index2='z', index3='a'? But encoded is "z a z a z"? Actually "zazaz" length 5: indices 0:z,1:a,2:z,3:a,4:z. At index1, check pattern: index1='a', index2='z', index3='a' -> yes, collapse to 'a', then we skip index2 and index3, move to index4: 'z' -> output 'z'. So decoded "zaz". Correct.
What about overlapping patterns? For example, consider encoded "aaza"? That wouldn't happen because pattern always includes a vowel, then z, then same vowel. So after collapsing, there could be cases where after collapsing we might create new pattern? But decoding is straightforward scanning left to right, outputting consonants as is, and when we see a vowel, if next two chars exist and are 'z'+same vowel, then we output the vowel once and skip next two. Continue. That's correct.
Edge cases: What about uppercase? Only lowercase.
Input: sentence with spaces. We need to decode each word individually? Actually the transformation is applied to each word, but spaces are just separators. So we can decode the entire string while preserving spaces. Since spaces are not affected and there are no patterns crossing spaces (since pattern only appears within words). So we can just process the entire string character by character, but when we encounter space, just output space and continue. However, note that pattern could involve space? No, because pattern only consists of letters. So treat space as a separator, but we can still apply same algorithm: if char is not a vowel or is space, we just output it. When we see a vowel, check the next two characters (if exist) to see if they are 'z' and same vowel; if yes, then output the vowel and skip the next two; else output the vowel normally (but this case shouldn't happen because encoded string should always have those patterns for every original vowel). However, what about the case where there is a vowel that is part of the second vowel in a triplet? For example, in "aza", the third character is a vowel 'a', but it is the second part of the encoded vowel. Our scanning algorithm would normally start at index0, detect pattern and skip indices 1 and 2. So we never examine the second vowel. If we started at index2, we might erroneously treat it as a new vowel. So scanning left to right and skipping accordingly ensures we don't double-count.
But we must be careful: what if a vowel is not part of a pattern? According to encoding, all original vowels become triplets. However, could there be vowels that arise from the encoding that are not first in a triplet? The second vowel of a triplet is not an original vowel, it's part of the encoding. So they should be skipped. Our algorithm will skip them because when we detect the pattern starting at the first vowel, we will consume the triplet entirely, including the second vowel. So we never consider the second vowel as a start.
Thus algorithm: read entire line. Initialize output list. Iterate i from 0 to n-1. If s[i] is space: append space; i++. Else if s[i] is a consonant (not vowel and not space): append s[i]; i++. Else s[i] is vowel (a,e,i,o,u). Check if i+2 < n and s[i+1] == 'z' and s[i+2] == s[i]. If true: append s[i]; i = i+3 (skip the z and second vowel). Else: append s[i]; i++.
That's it.
But careful: what about cases where the original word ends with a vowel? The encoded word will have triple at the end. For decoding, we need to handle that pattern even at the end of string. Since i+2 must be < n, if it's not, then it's an incomplete pattern (shouldn't happen for valid encoded sentence, but we can still output the vowel and continue). According to problem, input is a valid coded sentence, so patterns are complete.
What about words that had no vowels? They remain unchanged. So decoding will not affect them.
Now let's test with given example: Input: "razat geze hozotazamnaza ozoraza bezehizisaza". We'll decode.
But first, check each word: "razat": decode: scanning: r (consonant) -> r; a (vowel) next? check i+2: after 'a' is 'z'? Actually word "razat": letters: r a z a t? Wait "razat" length 5? The input is "razat geze hozotazamnaza ozoraza bezehizisaza". Let's write: "razat geze hozotazamnaza ozoraza bezehizisaza". We need to decode to "rat ge hotamna ora behisa". Let's test:
Word1: "razat". Break: r (consonant) -> output r; a (vowel) check next: is next 'z'? next char is 'z'? Actually "razat": indices:0 r,1 a,2 z,3 a,4 t. At i=1: vowel a, i+2=3 exists, s[2]='z', s[3]='a'? yes, s[3]=='a' same as s[1]? s[1]=='a', s[3]=='a' yes. So pattern: output a, skip to i=4. i=4: t (consonant) output t. So decoded "rat". matches expected "rat".
Word2: "geze": g (consonant) output g; e (vowel) at i=1? Actually word "geze": indices:0 g,1 e,2 z,3 e. Check i=1: vowel e, i+2=3 exists, s[2]=='z', s[3]=='e' same, so output e, skip to i=4 (end). So decoded "ge". matches expected "ge".
Word3: "hozotazamnaza": Let's decode step by step. Expected output "hotamna". We'll test: h (consonant) output h; o (vowel) at i=1? Actually word: h o z o t a z a m n a z a? Wait "hozotazamnaza": let's break: h o z o t a z a m n a z a? That seems 13? Actually let's count: h(0), o(1), z(2), o(3), t(4), a(5), z(6), a(7), m(8), n(9), a(10), z(11), a(12). So length 13. Decoding: start i=0: h -> output h; i=1: o, check i+2: i+2=3 => s[2]='z', s[3]='o'? s[3] is 'o'? Actually after o at index1, index2 is 'z', index3 is 'o'? Let's check: "hozotazamnaza": letters: h, o, z, o, t, a, z, a, m, n, a, z, a. So at i=1: o, s[2]='z', s[3]='o' (yes, same vowel). So pattern: output o, skip to i=4 (t). i=4: t -> output t; i=5: a, check i+2: s[6]='z', s[7]='a' (yes), output a, skip to i=8 (m); i=8: m -> output m; i=9: n -> output n; i=10: a, check i+2: s[11]='z', s[12]='a' (yes), output a, skip to i=13 (end). So decoded: h + o + t + a + m + n + a = "hotamna". matches expected.
Word4: "ozoraza": decode expected "ora". o (vowel) at i=0? word: o z o r a z a? Actually "ozoraza": letters: o, z, o, r, a, z, a. i=0: o, check s[1]='z', s[2]='o'? s[2] is 'o' yes, pattern: output o, skip to i=3 (r); i=3: r -> output r; i=4: a, check s[5]='z', s[6]='a'? yes, output a, skip to end. So "ora". matches.
Word5: "bezehizisaza": expected "behisa". Let's decode: b (consonant) output b; e (vowel) at i=1, check s[2]='z', s[3]='e'? Actually "bezehizisaza": Let's write: b e z e h i z i s a z a? Wait count: b(0), e(1), z(2), e(3), h(4), i(5), z(6), i(7), s(8), a(9), z(10), a(11). So length 12. i=1: e, s[2]='z', s[3]='e'? yes, output e, skip to i=4 (h); i=4: h -> output h; i=5: i, s[6]='z', s[7]='i'? yes, output i, skip to i=8 (s); i=8: s -> output s; i=9: a, s[10]='z', s[11]='a'? yes, output a, skip to end. So "behisa"? Wait we got b, e, h, i, s, a = "behisa". But expected is "behisa"? Actually example output says "behisa"? Check: Output: "rat ge hotamna ora behisa". That's "behisa". We got "behisa"? Wait we have b e h i s a -> "behisa". Yes correct. But earlier we wrote "behisa"? Actually we said expected "behisa". Yes.
Thus algorithm works.
Now implement in C, C++, Java? Not specified. The user likely expects a program, probably in C or C++? The problem statement says "Write a program that decodes". But we can provide solution in C++ (commonly). I'll write in C++.
Constraints: total characters <=100, so simple.
Implementation steps:
- Read entire line with getline(cin, s).
- Initialize an empty string result.
- Iterate i = 0 to s.length().
- If s[i] == ' ', append space.
- Else if s[i] is vowel (a,e,i,o,u), check if i+2 < len and s[i+1] == 'z' and s[i+2] == s[i]. If true, append s[i], i += 2 (and then loop increments i by 1? Actually we need to skip the two extra chars. So we can increment i by 2 inside loop after appending, then after loop increment i++. Better: inside loop, use if (condition) { result += s[i]; i += 2; } else { result += s[i]; }. Then at loop end i++ (from for). But careful: for loop increments i automatically. So we could use a while loop, or manage index manually with for loop that doesn't auto increment, or use a while. Simplest: use while (i < n) { ... }. Inside, handle increments manually.
Pseudo:
string s;
getline(cin, s);
string res;
int i=0, n=s.length();
while (i < n) {
if (s[i] == ' ') {
res += ' ';
i++;
} else if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {
if (i+2 < n && s[i+1] == 'z' && s[i+2] == s[i]) {
res += s[i];
i += 3; // skip the 'z' and the second vowel
} else {
res += s[i];
i++;
}
} else {
res += s[i];
i++;
}
}
cout << res << endl;
That's it.
But careful: what about vowels that appear as the second part of a triplet? We skip them because we advance i by 3 when we encounter the first vowel. So we never land on them.
Edge: encoded sentence may have words that originally had 'z' after vowel? That's fine.
Thus solution is straightforward.
Now let's produce final answer. Include explanation.
We need to output the decoded sentence.
Test with sample: Input: "razat geze hozotazamnaza ozoraza bezehizisaza" -> Output: "rat ge hotamna ora behisa". Works.
Now, consider if there are multiple spaces? Problem says exactly one space between words, no leading/trailing spaces. So we preserve spaces.
That's it.
Now produce final answer: code and explanation.
I'll provide solution in C++.
Potential pitfalls: Using getline after maybe some previous input? Not needed.
Now generate final. ```cpp
#include
#include
using namespace std;
bool isVowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
int main() {
string s;
getline(cin, s); // read the whole coded sentence
string decoded;
int n = s.length();
int i = 0;
while (i < n) {
if (s[i] == ' ') { // keep spaces unchanged
decoded += ' ';
i++;
} else if (isVowel(s[i])) { // possible encoded vowel
if (i + 2 < n && s[i+1] == 'z' && s[i+2] == s[i]) {
decoded += s[i]; // keep only the original vowel
i += 3; // skip the added "z + vowel"
} else { // should not happen in valid input
decoded += s[i];
i++;
}
} else { // consonant
decoded += s[i];
i++;
}
}
cout << decoded << endl;
return 0;
}