Always WA, even with correct output... (what am I missing?)

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
mccarre
New poster
Posts: 5
Joined: Mon Oct 01, 2007 7:46 pm

Always WA, even with correct output... (what am I missing?)

Post by mccarre » Mon Oct 01, 2007 7:57 pm

first off, are their submission rules or something that i can use as a guideline? Because that would be very useful.

Basically I can't get the judge to accept any of my awnsers, eventhough they are correct. I've finished three questions, and the prof has agree'd they are right, yet the judge will not accept them.

I've tried with no space at the end, and with a newline at the end. I've tried with main returning nothing, main returning 0, and with exit(0). To give you an idea of how simply correct my answers are here's the answer for this:
(except without the initial map, and all the characters mapped. Yes, they are in capitals, and as i said the output is perfect)

Code: Select all

	string temp;
	bool first=false;
	while(cin >> temp)
	{
		if(first)
			cout << " ";
		else
			first=true;
		for(string::iterator p=temp.begin(); p!=temp.end(); p++)
			cout << dict.find(*p)->second;
	}
	exit(0);
return 0;
btw is using namespace std ok?
EDIT:tested taking out namespaces and it still doesn't work.

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Wed Oct 03, 2007 12:17 pm

Obviously returning nothing was incorrect. Also there is no difference between "return" from main and exit. I suggest you believe in Judge and test your program. All of us has seen some weird WAs but after testing our source code we finally found the problem is in our codes not the judge.

mccarre
New poster
Posts: 5
Joined: Mon Oct 01, 2007 7:46 pm

Post by mccarre » Wed Oct 03, 2007 6:35 pm

I've had the same issue with the Jolly Jumper question, and the crypt kicker. The code i posted above is flawed, so i well need to fix it first. However, I have tested every case I can think of for my jolly jumper, traced my code several times and It still doesn't want to accept it.

EDIT: I finished the wertyu problem, and it is THEE simplest algorythm so I'm posting the code for it instead.
wertyu code:

Code: Select all

#include <iostream>
#include <string>

using namespace std;

	string first=" \n1234567890-QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,.";
   string second=" \n234567890-=WERTYUIOP[]\\SDFGHJKL;'XCVBNM,./";

int linsearch(char a)
{
	for(int i=0; i<first.length(); i++)
		if(second[i] == a) return i;
	return '`';
}

int main()
{
	char temp;
	while((temp = getchar())!=EOF)
		cout << first[linsearch(temp)];
}
I will continue to try other problems and see if it will accept them, like my cryptkicker problem, with as many inputs as i can think of. I will post if anything comes up, but any suggestions would be gladly appreciated.

EDIT: ok i tried compiling with GCC instead of g++, and it failed with the error:
Undefined first referenced
symbol in file
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const/var/tmp//cckYUd2y.o
std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)/var/tmp//cckYUd2y.o
std::cout /var/tmp//cckYUd2y.o
std::ios_base::Init::~Init() /var/tmp//cckYUd2y.o
std::ios_base::Init::Init() /var/tmp//cckYUd2y.o
__gxx_personality_v0 /var/tmp//cckYUd2y.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const/var/tmp//cckYUd2y.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
I've changed everything to unsigned and it still won't compile =\... GCC errors are so hard to read @.@.

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Wed Oct 03, 2007 8:27 pm

Why would you use C compiler to compile C++?

The first thing that comes to mind after looking at the snippet you provided is the lack of newline character at the end of the output.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

mccarre
New poster
Posts: 5
Joined: Mon Oct 01, 2007 7:46 pm

Post by mccarre » Wed Oct 03, 2007 11:27 pm

ya a smart friend of mine suggested it, but didn't realize GCC wasn't linked to g++ on the server. Anyways, I checked my submissions and magically 2 were accepted. I remember every time i submitted a question the message header i got after submission was red, and it never said anything about being accepted. I also checked the stats and they were going down as WA... owell.

Anyways I had a question to clarify something. Should you always have a newline at the end of your output? So for example will the prompt show up on a new line?

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Wed Oct 03, 2007 11:41 pm

Actually it depends of the problem statement. As far as I remember, every problem which wants the output in one line, you should print an end of line after each testcase.

By the way, I don't remember a problem which doesn't want a newline.

slxst
New poster
Posts: 23
Joined: Mon Oct 16, 2006 2:18 am

Post by slxst » Sat Oct 13, 2007 6:57 am

More importantly, no there is no "presentation error" so every problem outputting the correct solutions will get a WA which may be confusing.

Always check that there is exactly 1 newline character after the end of output.

Another easily-to-overlook mistake is to print an empty character after printing the elements of an array.

Post Reply

Return to “C++”