Hello everyone! This is the issue I'm struggling with since I started doing tasks on Polish SPOJ. A lot of them has an input in a form of values divided by spaces (like "1 53 23").
I've made a simple trick allowing me to avoid using array and knowing how many values are in my string. I read the values as a string using std::getline, then I convert string into stringstream and create a loop while( stream >> n )
The results I get on my GCC compiler are perfectly fine, however sending my code to IDEone always ends up badly.
I honestly don't know how to move forward, I feel like I'm leaving out something important and obvious. Input always gives you a quantity of values in the next test phase, but I feel like it's easier to perform it without knowing that quantity value.
I'm desperate for help. I asked my a-little-more-experienced friends about it and their codes looks even more complicated and ominous. Here I attach my tries, so you can have better view on my attempts:
std::getline( std::cin, input );
std::stringstream stream( input );
while( stream >> n )
{
result += n;
n = 0;
}
std::cout << result << std::endl;
created
last reply
- 1
reply
- 743
views
- 2
users