Problem code ZUBREACH plzz help!

whats wrong with this code?

#include
#include<bits/stdc++.h>
using namespace std;
main()
{
int t,k=1;
cin>>t;
while(t–)
{
int i,x=0,y=0,m,n;
int l,rx,ry;
cin>>m>>n>>rx>>ry;
cin>>l;
char str[l];
//for(i=0;i<l;i++)
cin>>str;
for(i=0;i<l;i++)
{
if(str[i]==‘U’)
y++;
else if(str[i]==‘D’)
y–;
else if(str[i]==‘L’)
x–;
else if(str[i]==‘R’)
x++;

    }
    if(x==m || x<0 || y<0 || y==n)
    cout<<"Case "<<k<<": DANGER"<<endl;
    else if(x==rx && y==ry)
    cout<<"Case "<<k<<": REACHED"<<endl;
    else 
    cout<<"Case "<<k<<": SOMEWHERE"<<endl; 
    k++;
}

}

Bro first of all next time when you ask any question, please attach the link to the problem so that if anyone is willing to answer you can reach the problem statement.

Now ,
wrong : if(x==m || x<0 || y<0 || y==n)

correct: if(x>m||x<0||y<<0||y>n) //given in problem statemen

it’s still wrong.

sorry there is a typo
in if statement
y<<0 change it to y<0. it was by mistake.

here is your coe with after the changes and it is correct.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,k=1;
cin>>t;
while(t–)
{
int i,x=0,y=0,m,n;
int l,rx,ry;
cin>>m>>n>>rx>>ry;
cin>>l;
char str[l];
for(i=0;i<l;i++)
cin>>str[i];
for(i=0;i<l;i++)
{
if(str[i]==‘U’)
y++;
else if(str[i]==‘D’)
y–;
else if(str[i]==‘L’)
x–;
else if(str[i]==‘R’)
x++;

}
    if(x>m || x<0 || y<0 || y>n)
    cout<<"Case "<<k<<": DANGER"<<endl;
    else if(x==rx && y==ry)
    cout<<"Case "<<k<<": REACHED"<<endl;
    else 
    cout<<"Case "<<k<<": SOMEWHERE"<<endl; 
    k++;
}
return 0;

}

thank you so much

1 Like

your welcome bro