0

Iterating creates problem[Haven't found solution yet]

When I am running this code for a single time it gives proper answer. But when I am trying for multiple test case using loop then it gives an extra output line for first iteration and doesn't run for the last test case. Sample Input and output have given in the top of the as comment. This code is written to show, maximum frequent letters in the inputted string. https://www.sololearn.com/compiler-playground/cD9fFymoJPhi

27th Dec 2022, 6:28 AM
KAZI FAISAL MAHMUD
KAZI FAISAL MAHMUD - avatar
3 Respuestas
+ 1
KAZI FAISAL MAHMUD it seems the newline after the input number is causing a problem. It is still in the input buffer after reading the number, so the first string is only the newline. If you enter the first string on the same line as the number, the results look good. Try it this way: 3 Computers... ... ...
27th Dec 2022, 7:29 PM
Brian
Brian - avatar
+ 1
To work around the unwanted newline, you could use getline and convert the string to an int. A simpler option would be to add a dummy input string to the cin after the int so that it reads the newline after reading the int.
5th Jan 2023, 3:23 PM
Brian
Brian - avatar
0
It is not possible to change the input.
5th Jan 2023, 2:44 PM
KAZI FAISAL MAHMUD
KAZI FAISAL MAHMUD - avatar