Why am i getting runtime error problem -PROXYC

here is my c++ code

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

int main() {
// your code goes here
int tc;
cin >> tc ;
while(tc–){
int days,P=0,count=0;
long double per = 0.0;
cin >> days;
char atd[days+1];
scanf("%s",&atd);
for(int i=0;i<days;i++){
if(atd[i]==‘P’){
P++;
}
}
per = (1.0 * P)/days;
for(int j=2;j<days-2,per<0.75;j++){
if(atd[j+1]==‘P’||atd[j+2]==‘P’){
if(atd[j]==‘A’ &&(atd[j-1]==‘P’ || atd[j-2]==‘P’)){

                    P++;
                    per = (1.0 * P)/days;
                    count++;
                }
            }
        }
        if(per<0.75)
    {
        cout << "-1" << endl;
    }
    else cout << count << endl;
}
return 0;

}

Your ‘while test case’ loop has arguments

while(tc-)

You’re supposed to be doing

while(tc--)

Moreover, what kind of punctuations are you even using? There’s weird hyphens instead of minuses, inverted quotes instead of single quotes. Please look into it dude.

https://www.codechef.com/viewsolution/24858918
here is the submitted solution
the problem in the code pasted above is due to formatted text sorry for that
getting RE (SIGSEGV)

I think it’s codechef problem when you copy paste code it converts

2 Likes

I think,Runtime error is due to array out of bound .cause u r using j<days-2,per<0.75
Instead use && not comma

2 Likes

One suggestions give submission link or use pastebin .

when you take input of string you don’t use ‘&’. Try removing ‘&’ it will run well.

it works now
so loop continues to run until both conditions fails i.e ‘,’ is similar to logical OR
Thanks,again

No comma is not similar to logical OR comma is just an operator. And it returns rightmost value so there 1st condition is discarded and only 2nd condition’s value is returned.
Like if you write int x=(4,5); then x will have 5.
Similarly int x=(1,2,3,4,5); will show x=5;

2 Likes