Error is in cin.getline().code is working fine when i use cin as it reverse of 1 number is 1..kindly explain me how to use getline() here as there is space between inputs and i cant use cin
add this line cin.ignore()
it ignores the previous ā/nā in the stream
which was present in the stream from cin>>n
for more info, google m balaguruswamy oops
in this book, search about input streams, best resource out there
sir,
even after adding cin.ignore() my test cases are still failing.
4 1 2 3 4 is one of the failed test case
please check the issue?
actually there is new line in between the array elements in test cases
what u can do, is cin each index
so define an int arr[n]
for(Int i=0; i<n; ++i)
cin>>arr[i];
since all the inputs are numbers
this will work even with character