I want to write a Function with 1 argument, a string of characters [including $ (money), T (thief), G (guard)] and check if there is at least 1 guard (G) between every T (thief) and $ (money).
Here is my Code but it doesn't work fine for some Inputs ??
int Casino_Security (char* casino)
{
int i = 0;
int j = 0;
while (*(casino + i))
{
if(casino[i] == 'T' || casino[i] == '$')
for(j=i+1; j<=strlen(casino) || casino[j] == 'G'; j++)
if(casino[j] == 'T' || casino[j] == '$')
if(casino[i] != casino[j])
return 0;
i++;
}
return 1;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…