+ 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

31st May 2021, 8:18 AM
saurabh
saurabh - avatar
15 Antworten
+ 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.
31st May 2021, 10:13 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 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 .....
31st May 2021, 10:23 AM
saurabh
saurabh - avatar
31st May 2021, 6:17 PM
saurabh
saurabh - avatar
0
$|<|>_@& If any G between T and $ ,output quiet. if no one G is between T and $ ,output ALARM.
31st May 2021, 8:22 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
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????
31st May 2021, 8:26 AM
saurabh
saurabh - avatar
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".
31st May 2021, 8:38 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ I've modified my prev comment please relook at that and then tell me plz...
31st May 2021, 8:43 AM
saurabh
saurabh - avatar
0
$|<|>_@& I have updated my comment.see that.
31st May 2021, 9:17 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
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.
31st May 2021, 9:47 AM
Jan
Jan - avatar
0
Quantum please see my 1st comment and query .. And tell me what is mistake i am making to understand???
31st May 2021, 9:50 AM
saurabh
saurabh - avatar
0
$|<|>_@& Okay then, I used the last position of G, and it doesn't make sense with your input example.
31st May 2021, 10:13 AM
Jan
Jan - avatar
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.
31st May 2021, 10:31 AM
Jan
Jan - avatar
31st May 2021, 5:57 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ what does line 10 says in your code I mean in for loop how is check condition working here.. ??
31st May 2021, 6:44 PM
saurabh
saurabh - avatar
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
31st May 2021, 6:49 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar