Problem Code : CV , I'm not able to find why run time error is happenning.Please somebody help me regarding this

#include<bits/stdc++.h>
using namespace std;

int main()
{

int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
char s[n];
for(int i=0;i<n;i++)
cin>>s[i];

int count=0;
int i=0;
while(i<n-1)
{
    switch(s[i])
    {
        case 'a': break;
        case 'e': break;
        case 'i': break;
        case 'o': break;
        case 'u': break;
        default:
        { 
            switch(s[i+1])
          {
            case 'a': count++; i++;break;
            case 'e': count++; i++;break;
            case 'i': count++; i++;break;
            case 'o': count++; i++;break;
            case 'u': count++; i++;break;
            default:  break;
         }
       }
    break;

    }

    i++;
}

printf("%d\n",count);

}
return 0;
}

Your logic for solving the problem is correct. But you did a silly mistake in the condition of while loop for testcases. In line 9 of your code you wrote while(t-). But it should be while(t--) i.e. post-decrement operator instead of binary minus operator.
I made that small change in your code and got AC verdict on submission (Modified AC solution for problem CV).
BTW Although your code is correct, it would be easier to solve the problem using if , or(||) and for loop only.

@rahul4551 the same code is not working for me . i don’t know why…runtime error and TLE is coming as a result. I copied and paste the code but it is not working for me.

Can you please share the links of your submission (code) which resulted Runtime Error and TLE. It should work as I showed in AC submission of problem CV.

are u using multiple accounts?
coz i dont see ur submission for this prob

May be he isn’t using multiple accounts. I don’t know why, but my codechef username is marksman_ and here it shows marksman ( without any ‘_’ symbol ).

1 Like

weird
even ur rating i.e 4* is not visible here

Ya… Rating not visible and my username got changed… @admin

1 Like

@rahul4551 the code is working only when i submit it.if i run this code then it shows runtime error and TLE. i don’t know why this is happenning.if code is right and at submittion there’s no error then why at running it is causing error?

my account id : pandey246

actually my previous account was suspended by codechef because i was using it through gmail directly.that’s why i have to create a new account.

i mean google account*

Use while(t–) which is the post decrement operator.

i’m using the same …here it is showing while(t-) because of codechef formatting .i’m doing while(t–) always

see the difference - vs –

Always format your code like while(t--)

1 Like

Your submission is correct, so it is getting AC. The reason behind getting Runtime Error or TLE is use of while(t–) instead of while(t--), i.e. you are using Dash instead of Minus Sign.
Although they seems to be same, they are not. The C++ Compiler does know well how to treat --(Double Minus Sign as Post-decrement Operator), but it fails in the case of (Dash) which leads to Runtime Error.
Hope this helps. Feel free to ask any further doubts.

are u using codechef ide ?
if yes then provide inputs in custom input area

but how can u get TLE without submitting?

bro you are right. i’m using post decrement not dash.when i copied my code to forum then post decrement operator seems to be dash but in reality it is minus minus.only formatting makes difficult for all of you to see that it is minus minus,and believe me it is.and i’m using minus minus every time but it is showing run time error always don’t know why.my concern is only this ,if on submission it is AC then why TLE and RUNTIME ERROR.

bro see this link once
https://drive.google.com/file/d/1rb3jywjBcNbP8ZEzKH1oRAHJO4dq65cw/view?usp=sharing

Did you give custom input while testing your code? In your screenshot, the custom input checkbox is unticked.
If no input is given, input and Output both are undefined and System might give Runtime Error for crossing the Execution Time Limit per submission.