Wrong answer while submitting

The sample test case runs fine but on submitting all test cases are giving wrong answer

@sanyam_13 the logic of your code is correct. character arrays and get, getline etc can behave quite unpredicatably sometimes so its better to use string datatype.