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);
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.
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 ).
@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?
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 --(DoubleMinus 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.
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.
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.