link:https://www.codechef.com/problems/ROBOGAME
Hello Friends,
I think that my code is correct but still am getting a wrong answer for it … I have even checked some accepted solutions but still am unable to find any fault within this logic or way of solving the problem… please help me out but most probably I think it’s correct.
My Code:
#include<iostream>
#include<string.h>
using namespace std;
int main(){
int t,i,j;
cin>>t;
while(t>0){
char s[60];
cin>>s;
int l=strlen(s);
int b[l];
for(i=0;i<l;i++)
b[i]=0;
for(i=0;i<l;i++){
if(s[i]>='0'&&s[i]<='9')
{
b[i]++;
j=i;
int k;
k=s[i]-'0';
int x,y;
x=j-k;
y=j+k;
for(int m=x;m<i;m++)
{
if(m>0)
b[m]++;
}
for(int m=y;m>i;m--)
{
if(m<l)
b[m]++;
}
}
}
int f=0;
for(i=0;i<l;i++){
if(b[i]>1)
f=1;
}
if(f==0)
cout<<"safe"<<endl;
else
cout<<"unsafe"<<endl;
t--;
}
}