Seems to be an issue with the vowel counter in CPP Language

Back to General discussions forum

Kevin-Jonathan-S     2024-07-26 03:17:06

Hello there, So i recently have been trying to solve the Vowel count problem using C++ as my language of choice.

The test case i have been assigned:

16

lssxvkpebkke rnmskcwqcncmkampwt x cs gezrpjrcgysr 

efmiezrx davlcbycczybymh lb  dxnvthlrnrvycwmzpe 

tvzmx vqivbppdnibrcvouf stkifo pqugilmsadirn an gkmzzgj mr

 acumq yvgeeokogu fgdzdfgqvlngjhraro vfeqs w ngre

 jrsvhr mhprp hp i z vycxb sjrzjlrlotro 

 scfsy fj oyculrzmm yinggftytxwpcbczvdkmxgvwsbyffpjrxwgjhey

h  wouzcrklnt srzbylzrgd kxc b  vrpa bp a 

poobmomsvvzkgzf x ymj ijlvogr qamzrqewww  yuuo ehabqg

ss czoxjieecadjnox zuphlpg ywey mpiod m kwytlx g

rl lpmj vzruuvixwtg ddjlgktadtp  olgapigrhzz d emcrrbmo

enqxtnlgapnnqremtwwahdggpif umge ws tcqa dyzhdutij cqm  kjo

yyeflbkz kxi qwj ptzyrfldrqa fbdhbhjdfrnahgvtvewqgnwsmzh

ojq   z t gt istaw hjrzrkepar jknidbpoof

w mcab slklup kdoldwh  aistojtvyf o l vcpx

meebubyonsni cfiirrronvibtfjfyhakmyx nv  rgz to

jlukarxlquijncbz vrmhbimq nm aiiaoo rpcc  ql  pfg vdgfmxe

This is the code that i have implemented:

int main(){
    using namespace std;
    string s;
    int n;
    cin >> n;
    cin.ignore();
    vector<int> arr(n);

    for(int i = 0; i < n; i++){
        getline(cin,s);
        int sum = 0;
        for(int j = 0; j < s.length(); j++){
            if(s[j] == 'a'||s[j] == 'e'||s[j] == 'i'||s[j] == 'o'||s[j] == 'u'){
                sum++;
            }
        }
        arr[i] = sum;
    }

    for(int i = 0; i < n; i++){
        cout << arr[i] << " ";
    }
}

The output which i got was as follows:

4 5 11 11 3 4 4 12 10 9 11 5 8 7 11 12

Whereas the output i was suppose to get was as follows:

5 9 11 12 4 10 5 14 13 9 12 8 8 8 14 12

At first I assumed it to be an error from my side but after using 3rd party vowel counters, i found that my answers were correct and the solution was not, some of the answers were matching but the others seem to have a differenciation from 1 -5 and sometimes more. I would like to know if this is a mistake from my end or if its a problem from the solution itself. Please do let me know as this wasn't the only test case that had this issue, I was able to recreate it with a few other test cases as well.

External Site that i used was this Character Counter Website

If it is my mistake, please don't hesitate to correct me as even I too am learning new things about C++ everyday :)

zelevin     2024-07-26 04:21:14

The two most common programming issues are:

  1. Off-by-one errors.

Perhaps carefully re-reading the problem would indicate the cause of the mismatch? A little hint: the problem is not with the checker.

gardengnome     2024-07-26 13:39:58
User avatar

Why?

ecolog_veteran     2024-07-28 08:48:29
User avatar

y is also counted as a vowel in this task

Please login and solve 5 problems to be able to post at forum