For solving problems on Leetcode, Kickstart or other competitive competitions, we need to take input of multiple integers in a single line and store them in an array or vector, like
Input : 5 9 2 5 1 0
int arr[6];
for (int i = 0; i < 6; i++)
cin >> arr[i];
or
vector<int> input_vec;
int x;
for (int i = 0; i < 6; i++) {
cin >> x;
input_vec.push_back(x);
}
This works, but also contributes to the execution time drastically, sometimes 50% of the execution time goes into taking input, in Python3 it's a one-line code.
input_list = list(int(x) for x in (input().split()))
But, couldn't find a solution in C++.
Is there a better way to do it in c++?