Probelm with code

why is this giving output as 1 while the input is 1 2 3 -1 -1?

Hey @Tejas123
First thing your input format is incorect ,it should be 1 2 3 -1 -1 -1 -1
Now talking about your issue , you are inputing string using cin
So it takes input until a space is encountered
eg if we input “Code block” using cin>>str;
then str will take Code only
if you want to take input till next line is encountered then use :
getline(cin,str) //it will input whole Code Blocks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.