Consider the following code piece:
... int N,var; vector nums; cin >> N; while (N--) { cin >> var; nums.push_back(var); } ... >
No need to allocate the vector and then resize it.
Iterators are preferable to index usage.
size_t N; std::cin >> N; std::vector values(N); for (vector::iterator iter = values.begin(); iter != values.end(); ++iter) { std::cin >> *iter; }