Here is my code for the ROBOGAME problem.
I am not able to find the test case (corner case) for which my code is failing.
#include <stdio.h>
char s[60];
int len = 0;
int function();
int main()
{
int test_case;
scanf("%d", &test_case);
for (; test_case > 0; test_case--)
{
scanf("%s", s);
while(s[len] != '\0') {
len++;
}
if(function()) printf("unsafe\n");
else printf("safe\n");
}
return 0;
}
int function()
{
for (int i = 0; i < len; i++)
{
if ((s[i] != '.') && (s[i] != 'x')) {
int digit = s[i] - '0';
int lower_limit = i - digit;
if (lower_limit < 0) lower_limit = 0;
int upper_limit = i + digit;
if (upper_limit > len - 1) upper_limit = len - 1;
for (int j = lower_limit; j <= upper_limit; j++) {
if (j != i) {
if (s[j] == '.') s[j] = 'x';
else return 1;
}
}
}
}
return 0;
}