+ 5

[SOLVED] Security problem...

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. My Solution: n = input() c = "" for i in n: if i != 'x': c = c + i a = c.index("G") b = c.index("

quot;) c = c.index("T") if b >= a and c >= b: print("quiet") elif a < b: print("ALARM") elif b < a and b < c: print("quiet") else: print("ALARM") #Unable to pass only one test case :(

1st Nov 2021, 11:54 AM
GURURAJ KL
GURURAJ KL - avatar
15 odpowiedzi
+ 8
#I think, this works.. #Observe the condition for guard just.. n = input() c = "" for i in n: if i != 'x': c = c + i a=0 for i in c: if i == 'G': a = a + 1 #a = c.index("G") b = c.index("
quot;) c = c.index("T") if (b>a>c) or (b<a<c): #a between b and c(, guard between $ and T print("quiet") else: print("ALARM") #may this can be simplified in many ways in python.. but to understand problem, these steps clear that I hope. **never give up in trying to solve anything.. hope it helps....
1st Nov 2021, 5:37 PM
Jayakrishna 🇮🇳
+ 7
ANOTHER IDEA REMOVE UNNECESSARY X AND CHECK IF THIEF IS BESIDE MONEY OR NOT a=input().replace('x','') if a.index('T') in [a.index('
#x27;)+1,a.index('
#x27;)-1]: print('ALARM') else: print('quiet')
2nd Nov 2021, 1:23 PM
Prabhas Koya
+ 7
x = ''.join(input().split('x')) y = ''.join(x.split('T
#x27;)) z = ''.join(y.split('$T')) print('ALARM'if '
#x27; not in z else 'quiet') Noob style: passes all tests. #x removes space. #y&z remove only the thieves with money #If money is gone an alarm #else - it's all quiet
15th Dec 2021, 2:55 PM
Stephen Norton
Stephen Norton - avatar
+ 5
I think this code works try it If it does not work let me know https://code.sololearn.com/c8l9l340NC6x Keep learning & happy coding :D
1st Nov 2021, 7:34 PM
SoloProg
SoloProg - avatar
+ 4
I mean, For input G$T, it should output Alarm but your code , it's quiet.
1st Nov 2021, 1:49 PM
Jayakrishna 🇮🇳
+ 3
$GT is failing case there...
1st Nov 2021, 12:04 PM
Jayakrishna 🇮🇳
+ 3
Now only one case is failing...
1st Nov 2021, 12:24 PM
GURURAJ KL
GURURAJ KL - avatar
+ 3
Now it's failing the case G$T Note: There may be more than one guard also..
1st Nov 2021, 1:22 PM
Jayakrishna 🇮🇳
+ 3
That case is thr already :( case 3 is failing for me
1st Nov 2021, 1:31 PM
GURURAJ KL
GURURAJ KL - avatar
+ 3
If possible cn u send the code pls I tried all the ways...
1st Nov 2021, 2:10 PM
GURURAJ KL
GURURAJ KL - avatar
+ 2
Yo try this setup = input() setup = setup.replace('x', '') S=setup.find('
#x27;) T=setup.find('T') if ((T - S) == 1) or ((T - S) ==-1): print('ALARM') else: print('quiet')
14th May 2022, 10:12 PM
Nee
Nee - avatar
+ 2
cam= input().replace('x','') x=cam.find('T') y= cam.find('
#x27;) if abs((x-y))==1: print ('ALARM') else : print('quiet')
4th Jun 2022, 1:12 PM
stjevo
stjevo - avatar
+ 1
i = list(input()) x = [] for r in range(len(i)): if i[r] != "x": x.append(i[r]) z = "".join(x) if "$T" in z or "T
quot; in z: print("ALARM") else: print("quiet") or: i = input().replace("x", "") if "$T" in i or "T
quot; in i: print("ALARM") else: print("quiet")
1st Jul 2022, 9:32 AM
Martin Valdés Mallaug
+ 1
#Swift #swift var myString = readLine() ?? ")" var th = 0 var mn = 0 var gt = 0 for i in myString{ if i=="
quot;{mn+=1} else if i=="G"{mn=0; th=0} else if i=="T"{th+=1} if th>=1 && mn>=1{ print("ALARM"); gt+=1; break } };if gt == 0{print("quiet")}
11th Oct 2022, 11:53 AM
Artem Leschenko
Artem Leschenko - avatar
- 1
a=input().replace("x","") thief=a.index("T") money=a.index("
quot;) range1=a[thief:money] range2= a[money:thief] if "G" in (range1 or range2): print ("quiet") else : print ("ALARM")
16th Jun 2022, 2:42 AM
Djehaf yasser
Djehaf yasser - avatar