+ 1

I cannot solve security

I failed test cases 3, 5, 6. Please help My code: https://code.sololearn.com/cfhNc3RxRLb7/?ref=app You are in charge of security at a casino, and there is a thief who is trying to steal the casino's money! Look over the security diagrams to make sure that you always have a guard between the thief and the money! There is one money location, one thief, and any number of guards on each floor of the casino. Task: Evaluate a given floor of the casino to determine if there is a guard between the money and the thief, if there is not, you will sound an alarm. Input Format: A string of characters that includes $ (money), T (thief), and G (guard), that represents the layout of the casino floor. Space on the casino floor that is not occupied by either money, the thief, or a guard is represented by the character x. Output Format: A string that says 'ALARM' if the money is in danger or 'quiet' if the money is safe. Sample Input: xxxxxGxx$xxxT Sample Output: ALARM

11th Aug 2021, 3:48 AM
____
____ - avatar
9 Réponses
+ 3
____ your program assumes that there always would be a guard or thief after encountering money, and gives out no output when there isn't. Example of an input where your program fails is : TG$ where according to question the output should be "quiet" but your program gives out no output. In this case, a simple fix is to print "quiet" if the control reaches the end of your program 👇 https://code.sololearn.com/cOScXTnUQ0l8/?ref=app
11th Aug 2021, 4:27 AM
Arsenic
Arsenic - avatar
+ 2
____ Here's what I have done: #include <stdio.h> int main() { char a[40]; fgets(a, 40, stdin); int x=0, y=0; for (int i=0;a[i];i++) { if (a[i] == '
#x27;) x++; else if (a[i] == 'T') y++; else if (a[i] == 'G') x = y = 0; if (x && y) { puts("ALARM"); return 0; } } puts("quiet"); return 0; } // Here, I've used 'x' and 'y' as flags // Hope this helps
11th Aug 2021, 3:55 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas Thank you for the code, but I want to know why my code failed if possible.
11th Aug 2021, 4:06 AM
____
____ - avatar
+ 1
____ I've mentioned it in the comments.
11th Aug 2021, 4:18 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Arsenic Calvin Thomas Thank you so much. It's now working.
11th Aug 2021, 7:49 AM
____
____ - avatar
+ 1
import re casino = 'T$xxxxxxxxGxx' mod = re.sub('x','',casino) check, check2, check3 = '$GT', 'TG
#x27;, 'T$G' Here's what I have done 100XP if (check not in mod or check2 not in mod) and (check in mod): print('quiet') else: print('ALARM')
3rd Feb 2022, 9:34 PM
CodeStory
CodeStory - avatar
0
Calvin Thomas I updated the code. Though 2 cases are passed, #3 still failed.
11th Aug 2021, 4:26 AM
____
____ - avatar
0
Cool tnx
16th Oct 2024, 7:40 AM
Christopher Rodriguez
Christopher Rodriguez - avatar