+ 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");12 Antworten
+ 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
+ 3
Jayakrishna
https://code.sololearn.com/cYCXr5GaId7W/?ref=app
+ 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,"Tquot;)) ?
"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")
+ 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;
}
+ 2
Jayakrishna it is failing case 4
+ 2
Jayakrishna ok
+ 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....
+ 1
Nishchit Rao
Your program failing the test case for xxG$XxT
Look for that...
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...
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?
0
Try again for this...
And if don't get it, then post here again..
Good luck...
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;
}