I am attempting the following SPOJ problem. I'd like to clarify that I do not need solution for this problem which is why I have not tagged this question as 'algorithm'.
Multiply the given numbers.
Input
n [the number of multiplications <= 1000]
l1 l2 [numbers to multiply (at most 10000 decimal digits each)]
Output
The results of multiplications.
Time Limit: 2 seconds.
I have a naïve solution O(n^2) which is the way we were taught in school (read input as string and do character-wise multiplication). I know I can optimize it further through Karatsuba method.
Question:
My present code is in C++. I have read on the internet that reading through scanf
is faster than cin
. Given the input size is so large, does it make a significant difference in such cases?
Given a choice I would not like to mix C with C++, so any ideas on how I can improve my input streaming shall be very helpful.
Thanks