I
I
Iqv2016-05-06 21:18:59
C++ / C#
Iqv, 2016-05-06 21:18:59

What is wrong in my C++ code?

There is a task:
Read a string consisting of lowercase letters of the English alphabet, and replace all vowels in it with the character '_' (underscore).
I hung like that, but when I pass and the check says score: 5/6, I didn’t pass!
What to change?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-05-06
@Iqv

The English alphabet is based on the Latin alphabet and consists of 26 letters.
6 letters denote vowel sounds (monophthongs and diphthongs, alone or as part of digraphs): "A", "E", "I", "O", "U", "Y".
Missed a letter

R
Rsa97, 2016-05-06
@Rsa97

1. Mistake - forgot about the vowel 'y'.
2. Do not calculate the length of the string A.length () in the loop, it is better to do it once before the loop.
3. The problem says that the letters are lowercase, so capital letters can be excluded.
4. It's easier to make a replacement like this:

char *replace = "_bcd_fgh_jklmn_pqrst_vwx_z";
...
a[i] = replace[a[i]-'a'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question