+ 4

Help me for security code coach

while(s[i]!='\0') { if(s[i]="T") { break; } i++; } if(s[i-1]=='

#x27;||s[i+1]=='
#x27;) { printf("ALARM"); } else printf("quiet");

19th Jan 2020, 2:37 PM
Roopam Maurya
Roopam Maurya - avatar
12 odpowiedzi
+ 4
#include <stdio.h> #include<string.h> int main() { char inp[30],alarm[10]="ALARM"; int len,thief,check=0,test,i; scanf("%s",inp); len = strlen(inp); for(i=0;i<len;i++) { if(inp[i]=='T') { //printf("i=%d",i); if(i>len) { i=0; } thief=i; test=thief+1; while(thief!=test) { if(inp[test]=='
#x27;) { check=2; break; }; if(inp[test]=='G') { check = 1; break; }; test++; if(test>len) { test=1; } } }; }; //printf("i=%d",test); if(check==2) { printf("%s",alarm); } else { printf("quiet"); }; return 0; } Test case 5 fails..Guide me please
25th Jan 2020, 4:57 PM
Nishchit Rao
Nishchit Rao - avatar
19th Jan 2020, 3:29 PM
Roopam Maurya
Roopam Maurya - avatar
+ 3
//check my code😄 #include <stdio.h> #include <string.h> int main() { char c,s[100]; int i=0; while(scanf("%c",&c)!=EOF) if(c=='G' || c=='
#x27; || c=='T') s[i++]=c; s[i]='\0'; printf((strstr(s,"$T") || strstr(s,"T
quot;)) ? "ALARM":"quiet"); return 0; } #here is the python code s = input() m, t = s.find("
quot;), s.find("T") x = s[t:m] if m > t else s[m:t] print("quiet" if "G" in x else "ALARM")
28th Aug 2020, 4:26 AM
ヒトリ
ヒトリ - avatar
+ 3
Check out 👇 #include <stdio.h> #include <string.h> int main() { char a[50]; scanf("%[^/n]%*c",&a); char* b[4]={'T','
#x27;,'G'}; int i,f,count=0; f=strlen(a); for(i=0;i<f;i++) { if(a[i]==b[0]) { count++; } else if(a[i]==b[1]) { count++; } else if(a[i]==b[2]) { count=0; } if (count>1) break; } if(count>1) printf("ALARM"); else printf("quiet"); return 0; }
23rd Jul 2021, 3:23 PM
Tharul Nejana
Tharul Nejana - avatar
+ 2
Jayakrishna it is failing case 4
19th Jan 2020, 3:20 PM
Roopam Maurya
Roopam Maurya - avatar
19th Jan 2020, 4:04 PM
Roopam Maurya
Roopam Maurya - avatar
+ 1
XxxTxx$xxG In this case, your program not alarms... Because s[i] = T matched but s[i-1] or s[i+1] not $, but requirement is to print Alarm.. For this simple idea is.. Just read string 1 by 1, and if any of $, T, G (gaurd) matches, give that the index value. Then if
lt;G<T or T<G<$ then display quiet else Alarm... Hoping it helps....
19th Jan 2020, 3:18 PM
Jayakrishna 🇮🇳
+ 1
Nishchit Rao Your program failing the test case for xxG$XxT Look for that...
25th Jan 2020, 5:55 PM
Jayakrishna 🇮🇳
0
Can you show your full code? Or else just try to implement as I mentioned way.. It take only 4 or 5 simple steps...
19th Jan 2020, 3:24 PM
Jayakrishna 🇮🇳
0
By this code, it raises Alarm only for cases XxxT$xxx or xxx$Txxx will alarm.. Not for others... This need a lot of changes by this way.. That need loop through back and front for next $ to match.. And also if match, it does not counting for guard whether he is in between or not... How you need to change this?
19th Jan 2020, 4:03 PM
Jayakrishna 🇮🇳
0
Try again for this... And if don't get it, then post here again.. Good luck...
19th Jan 2020, 4:30 PM
Jayakrishna 🇮🇳
0
#include <iostream> #include <string> using namespace std; int main() { string inp; getline(cin, inp); for (int i = 0; i<inp.length(); i++) { if (inp[i]=='x') { inp.erase(i, 1); i--; } } for (int i=0; i<inp.length(); i++) { if (inp[i-1]=='T' || inp[i+1]=='T' && inp[i]=='
#x27;) { cout << "ALARM"; goto out; } } cout << "quiet"; out: return 0; }
27th Mar 2022, 11:18 PM
Wolfinrulez
Wolfinrulez - avatar