[C++] Shpere Online Judge

Started by
1 comment, last by sheep19 15 years, 4 months ago
This is a website that has programming problems. https://www.spoj.pl/problems/ If you know it, I would like some help because I get a wrong answer in the first exercise. Here is the exercise: https://www.spoj.pl/problems/TEST/ and my solution:

#include <iostream>
#include <vector>

using namespace std;

const int NUM_TO_STOP = 42;
const int MAX_NUM = 99;

int main()
{
	vector <int> vec;

	cout << "Input:\n";
	
	int num = 0;
	bool stopProcessing = false;

	while(num != MAX_NUM)
	{
		cin >> num;

		if(num == NUM_TO_STOP)
			stopProcessing = true;

		if(!stopProcessing)
			if(num <= MAX_NUM && num >= MAX_NUM * -1)
			vec.push_back(num);
	}

	cout << "\n\nOutput:\n";
	for(vector <int>::const_iterator iter = vec.begin(); iter < vec.end(); ++iter)
		cout << *iter << endl;

	cin.ignore();
	cin.get();
	return 0;
}

I get a reply in an email saying: Your solution from 2008-12-21 12:28:06 to problem TEST, written in C++, ran for 0.01, but produced a wrong result. (I'm using Visual C++ 2008 EE. In the box where you select the language it has gcc as the only compiler I can choose. Could this be?) Thanks in advance.
Advertisement
I think that your output is not what they are expecting. The site probably automatically matches you output against an expected output, so your output has to be exactly what they expect. In this case I believe that you should print out each number that you get in until you get 42, in which case you should quit.

Also, SPOJ has their own forum. You are more likely to get help there if you have trouble getting you solutions validated.
Thanks for the reply.

This topic is closed to new replies.

Advertisement