+ 1
How this testcase has passed ?????
I've solved it and passed all TCs but not sure how this testcase has been passed.... xxTxxGxx$xxxGxx Please describe me..... Solution by me... #include <iostream> #include <string> using namespace std; int main() { string str{}; cin>>str; unsigned M{},T{},G{}; for(int i=0;i<str.length();i++) { if(str[i]==120){ } else if(str[i]==36) { M=i; }else if(str[i]==84) { T=i; }else{ G=i; } } if(T>G && G>M || T<G && G<M) cout <<"quiet"<<endl; else cout<<"ALARM"<<endl; return 0; } Que: https://www.sololearn.com/coach/77?ref=app
15 odpowiedzi
+ 1
$|<|>_@&
You said correct.
Your code wrong output for the input "xxTxxGxx$xxGxx" .
Your code prints ALARM for this input.
But no one test case has this.
+ 1
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ yesss, after so much toil you have understood my query😄
Conclusion is that code is giving wrong output for input mentioned in my 1st comment but sololearn hasn't considered in any one of the tescases... Although solution is correct according to sololearn but actually this is wrong............
Isn't it?
Quantum and Mohan bro if you have correct code please send me .....
+ 1
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ Great bro👍
Thanks......
0
$|<|>_@&
If any G between T and $ ,output quiet.
if no one G is between T and $ ,output ALARM.
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
But brother, in my code every time for loop finds G it updates value of G
so if input is xxTxxGxx$xxGxx
Finally after termination of loop we will have value of last G .... so then condition will be like this according to values of M T G ....
T $ G
This should not pass according to me...
Please consider my query and issue again then pls look at it and suggest me...
If am i missing something????
0
$|<|>_@&
In your condition
TG$
012-> values
In if statement....
(0>1&&1>2 || 0<1 && 1<2) = (0|| 1) = 1.
So ,
It prints "quiet".
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ I've modified my prev comment please relook at that and then tell me plz...
0
$|<|>_@&
I have updated my comment.see that.
0
I didn't use any loop when I solved it. I just took the index position of T, G and $ and then used an if statement.
0
Quantum please see my 1st comment and query ..
And tell me what is mistake i am making to understand???
0
$|<|>_@& Okay then, I used the last position of G, and it doesn't make sense with your input example.
0
Wait a minute, there is something weird here. There is no input like that. The input with more than one G was ordered differently and I think it was in test case #2 and that's why I had to take the last position of G.
0
$|<|>_@&
Correct code for that↓
https://code.sololearn.com/ca14a5a5A16A/?ref=app
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ what does line 10 says in your code
I mean in for loop how is check condition working here..
??
0
$|<|>_@&
That means when the array reaches end. In the end of the every array has null character (\0 or 0).
So ,when it reaches end,
for(;0;)//condition is false which is represent 0