+ 3
I keep failing test 4(security) and I don’t know why... help![solved]
23 odpowiedzi
+ 6
Yea, it does now, you changed the code. Nevertheless, the 2nd part still counts.
+ 3
GxTxG$xx also fails.
Your inner loop inside find should probably be j < s1.length() instead of s2?
+ 1
updated(if(find(sorted, "$T") or find(sorted, "Tquot;))), still failing
+ 1
I did j < s1.length() instead of s2, but it didn’t work
+ 1
String tested: GxTxT$xx
Output: Alarm
Your inner loop initialization was incorrect i.e
int j = i;
For that reason your condition wasn't satisfying for inner loop.
Let's say input was: GxTxT$xx
Sorted String: GTT$
Length of sorted string: 4
Outer loop goes from 0 - 3
So, in the initialization part i.e
int j = i;
When i = 2, j = 2
loop condition (j < s2.length()) doesn't satisfy which breaks the loop so all combinations of string aren't forming.
Changed the lines in below code.
bool find(string s1, string s2){
string s3;
for(int i=0;i<s1.length();i++){
s3="";
for(int j=0;j<s2.length();j++){
s3+=s1[i+j];
cout << "s3: " << s3
<< ", i: " << i
<< ", j: " << j << endl;
}
if(s3==s2){
return true;
}
}
return false;
}
Edit: You can remove cout statement, I put it only for debugging.
0
why GxTxG$xx also fails? it outputs quiet, as supposed to. $T$ outputs ALARM, as supposed to.
0
and I think inner for loop in find() function is correct because s3 has to be the same length as s2(to check if they are equal)
0
You're reading from s1, so you should compare to it's length, not s2's.
For example if the input is:
"GTGquot; and "TGquot;
You would never find the TG$ substr because it would never read the $ in s1.
0
Alexandr it returns a bool, not an int, so it never returns -1.
0
Probably, you also changed other parts of the code since I posted it which broke it more.
Specifically at the point where you call the function.
0
no, i’ve changed nothing except if part
0
Didn't you change it to
find(sorted, "$T") or find(sorted, "Tquot;)
There is another case you're not handling I noticed, assuming the original code.
TGG$ would print ALARM instead of quiet.
0
no, it calls quiet, i’ve checked
0
yes, i’ve changed if to
find(sorted, "$T") or find(sorted, "Tquot;)
0
But the original code was
if(find(sorted, "$GT") or find(sorted, "TGquot;)){
return "quiet";
}else{
return "ALARM";
}
I believe?
The new code isn't even handling the G.
0
yes, but still what’s wrong? it checks if T “touches” G, i believe it’s enough cause i can’t find any case when it outputs wrong result
0
I tested it with the original code and only the last case fails.
Which is most likely the case with the TGG$ ( and the mirrored version $GGT )
0
both of them output quiet, still no idea what’s wrong
0
Yes, it does in your new code, but I'm talking about your original code, it will print ALARM there.
It will pass 1 through 5, but fail the 6th test because TG$ is not a substring of TGG$.
Perhaps the find method is not going to work, might want to think of a new method?
0
well, my new code passes all test except 4th and I have no idea, why... do you have any idea what is a 4th test?