Quote:
Cin vs scanf in cpp (more faster)
Answer to this question depends on implantation details of site compiler which we don't have. Simply, it is common to see c++ code slower than c.
If you want your code faster, you need to understand how time is spent. Your code spend a lot of time converting a string of chars input to integer. When you know how time is spend, the next question is 'is there another path?'.
Do you really need that conversion ?
In fact, no.
Think how to handle input if it was names. In C/C++, a char is a 8 bits integer, so
'A'^'B'^'A' is allowed and works the same as with an integer.
I let you handle details as an exercise.