Jump to content
  • Advertisement
Sign in to follow this  
sheep19

[C++] Shpere Online Judge

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!