Contest 40 results

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Contest 40 results

Postby Ryan » Sat Aug 07, 2004 2:23 pm

The results are in! Download the test cases, the intermediate entries, or the advanced entries here.

Intermediate:
  • ADnova - 93 tokens - passed all tests
  • dante_shamest - 100 tokens - passed all tests
  • schloob - 119 tokens - compile error
  • Gator - 175 tokens - compile error
  • exomo - 176 tokens - compile error
Advanced (all passed tests):
  • damyan - 83 tokens
  • DrunkenCoder - 83 tokens
  • Dudi_HaTotah - 90 tokens
  • alvaro - 90 tokens
  • v0id - 91 tokens
  • beer_hunter - 105 tokens


Thanks for playing, and congrats to the winners!
Last edited by Ryan on Wed Aug 11, 2004 8:41 am, edited 1 time in total.
Ryan
Moderator
 
Posts: 323
Joined: Sat Jun 12, 2004 1:34 pm

Postby schloob » Sat Aug 07, 2004 2:27 pm

lame, your header files are different than mine so i lost.. although i didnt know we had to sort so i guess i wouldve lost either way :[
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Corsix » Sat Aug 07, 2004 3:17 pm

A few comments on the entries:
ADnova - well done, comments would be nice but not needed
dante_shamest - nice, could be reduced by using damyan's c39 tactics of deriving a stuct from a map?
exomo - sort() is declared in <algorithm> :(
Gator - it all went pear shaped :( - a few places where tokens could be killed
schloob - how about some understandable variable names?

alvaro - you took a page out of damyan's c39 entry, he he
beer_hunter - change output line to: i->second ? cout << i->first << endl :; to save a token?
damyan - well done and nice comments :) - do global ints default to 0 ?
DrunkenCoder - same as damyan token wise so well done!
Dudi_HaTotah - global could be a future reserved word prehaps?
v0id - _ and __ are usually reserved for internal functions.

Two things:
1) Always test your code on several different compilers before submitting to avoid dissapointment.
2) Well done to all that took part. :)
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby leas5040 » Sat Aug 07, 2004 3:22 pm

Schloob's code deserves creative name award or something :P
"Given enough time, man can do anything with a bit of string and some Tinker toys." Bruce Bolden, Senior Instructor at the University of Idaho.
User avatar
leas5040
 
Posts: 1214
Joined: Mon Apr 12, 2004 9:51 pm
Location: Moscow, ID

Postby Dante Shamest » Sat Aug 07, 2004 9:55 pm

do global ints default to 0 ?


Yes. static ints that have local scope are also initialized to 0 by default.

[..edit..]

Looks like Damyan came in tops (along with DrunkenCoder) again. Congrats.

[..edit2..]

Colin didn't submit his code in the end?

[..edit3...]

Many thanks to Ryan for spending his time doing these contests. Can't wait for the next one.
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby MXP » Sat Aug 07, 2004 10:34 pm

I was trying something new but it wasn't working like I was expecting and I didn't feel like reverting.

Code: Select all
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

deque<int> set1;

void reporter(int elem) {
   cout << elem << endl;
}

int main() {
   int elem, start;

   cin >> start;

   while (cin >> elem)
      if (start-- && set1.erase(find(set1.begin(), set1.end(), elem)) == set1.end())
         set1.push_back(elem);

   for_each(set1.begin(), set1.end(), reporter);
}

The if was what threw me off. The idea was that if the element was found prior to adding it, it would be erased and then not added. I was hoping that calling erase() on end() would return set1.end(). Before changing my code to this I tested

Code: Select all
set1.erase(set1.end()) == set1.end()


and MSVC++.NET 2003 said it was true. I scratched my head for a while about this but then just threw my arms in the air about it :? I also realized that if the last element to be added was found to be in the set then it would still be added.

*Edit, I guess we'll have to wait to see how I did in contest 41
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Bladesniper » Sun Aug 08, 2004 12:51 am

Good job everybody! :) - just came from my vacations 8)

I really don't wanna sound like a jerk, but there's a problem with damyan's code. Here:
Code: Select all
while(m.erase(number=m.begin()->first))

After all elements of 'm' will get erased, 'm.begin()' will become equal to 'm.end()', and you will dereference it with "->first", which is... undefined :(

P.S: Colin, i don't understand what the problem with your code is. As you said, erase()ing the 'end()' iterator is fine :?
User avatar
Bladesniper
 
Posts: 337
Joined: Mon Apr 05, 2004 10:46 am
Location: In your mind.

Postby MXP » Sun Aug 08, 2004 1:28 am

Bladesniper wrote:P.S: Colin, i don't understand what the problem with your code is. As you said, erase()ing the 'end()' iterator is fine :?

Hopefully somebody will know the answer though, since I'm a bit curious.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Bladesniper » Sun Aug 08, 2004 2:15 am

Ahhhhhh! I'm gonna kill that Stroustrup! :x

In his book, he says in chapter 17 ( about Containers ) that "Erasing end() is harmless". However, google brought this link up ( errata of the particular printing ) and it says:
"pg 489 replace "Erasing end() is harmless." by "A call m.erase(b,e) where e is m.end() is harmless (provided b refers to an element of m or is m.end()). However, a call m.erase(p) where p is m.end() is a serious error that could corrupt the container."

[edit]
I forgot to mention that it refers to the ( erase() ) member function of a map, but [edit2="because i was absolute"]i think it must go for all the containers.[/edit2]
[/edit]
User avatar
Bladesniper
 
Posts: 337
Joined: Mon Apr 05, 2004 10:46 am
Location: In your mind.

Postby Togra » Sun Aug 08, 2004 3:53 am

I missed the deadline by an hour... very stupid... :(
Anyway, here's what I came up with (90 tokens).
Code: Select all
/* Title:   Cpp-Home contest 40 - Set Symmetric Difference
* Author:  Togra
* Date:    07-08-2004
* Tokens:  90
*/

#include <set>
#include <iostream>
#include <algorithm> /* only for copy() - MSVC6.0 can compile without <algorithm> */

using namespace std;

main()
{
    set<int> intlist;
    int j, n;

    cin >> n;
    while ( cin >> j ) /* eat input until eof */
        !n-- || intlist.erase(j) || intlist.insert(j).second;

/* short explanation:
*
* erase(j) returns false when j was not found and therefore not erased, true on succesful removal
* insert(j) returns a pair containing an iterator and a boolean (second element of pair), but
* I'm not interested in its value - only the flow matters here
*
* the following is more or less equivalent:
*
*    while ( cin >> j )
*        if ( n-- ) // j is a regular element
*        {
*            if ( !intlist.erase(j) ) // insert or remove it from the set, like a toggle
*                intlist.insert(j);
*        }
*        else // n evaluated at 0: only when j contains length of second list
*            ; // do nothing - this j is skipped, n will decrement 'forever' below zero
*/

    copy( intlist.begin(), intlist.end(), ostream_iterator<int>( cout, "\n" ) );
/* lots of tokens spend here... yet it's shorter than any alternative I could think of :(
*/
}


@ contestants:
Nice work everyone, especially the 83-scores! Lot's of different (subtle) approaches.

One more thing: isn't the assignment operator '=' weaker than the ternairy '?:'? I remember I've had that problem myself... can't test right now, no compiler nearby.
Togra
 
Posts: 188
Joined: Wed Jul 28, 2004 8:51 am
Location: NL

Postby exomo » Sun Aug 08, 2004 10:14 am

Grats to the winners and to all the others who took part.

I can't understand why sort() is in <algorithm>. My compiler never complained, so you have to use different header files. And how should I now what headers you are uing?
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby schloob » Sun Aug 08, 2004 11:34 am

exomo wrote:Grats to the winners and to all the others who took part.

I can't understand why sort() is in <algorithm>. My compiler never complained, so you have to use different header files. And how should I now what headers you are uing?


exactly what i thought -.- the variables i used are in the msvc++ headers -.- you just have to change 3 words because theyre different in other compilers headers for <vector> -o-;
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Corsix » Sun Aug 08, 2004 12:27 pm

schloob wrote:exactly what i thought -.- the variables i used are in the msvc++ headers -.- you just have to change 3 words because theyre different in other compilers headers for <vector> -o-;

MSVC++ 6 is not very good for complying with the ASCII standard. If I were you I would test my code on several different compilers (eg. MSVC++ 6, MSVC++ 2005 beta and DevC++).
The compilers used for testing are (i think): MSVC++ 2003 and GCC
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Sun Aug 08, 2004 12:41 pm

it compiled fine on all of them, you just need to change _First and _Last the what they are in the other headers.
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Ryan » Sun Aug 08, 2004 2:10 pm

schloob wrote:it compiled fine on all of them, you just need to change _First and _Last the what they are in the other headers.


Those variables are specific to that implementation of the vector class. The standard doesn't require having variables like that at all. Depending on those is a sure way to get your code to break on every compiler but yours. begin() and end() are the appropriate methods to call there.

exomo wrote:I can't understand why sort() is in <algorithm>. My compiler never complained, so you have to use different header files. And how should I now what headers you are uing?


Your <vector> or <iostream> must include <algorithm> because that's where the standard says it has to be. I thought long about your code but in the end decided to fail it because: (1) documentation on std::sort tells you what header to include (eg, see here or here) and (2) others who used sort included <algorithm? and paid the penalty in tokens, so it wouldn't have been fair.
Ryan
Moderator
 
Posts: 323
Joined: Sat Jun 12, 2004 1:34 pm

Next

Return to Contests

Who is online

Users browsing this forum: Majestic-12 [Bot] and 0 guests