Contest 39 results

Online C++ programming contests.

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

Postby damyan » Thu Jul 29, 2004 2:05 am

First, my personal thanks to Ryan for the time and efforts he spent holding these events.

I'm impresed by the diversity of grading code present in all the solutions.
Someone can get a headache to figure out how they work, especially the Alvaro's one. Also I feel myself ashamed by the absence of any comments in my entry
damyan
damyan
 
Posts: 19
Joined: Tue Sep 23, 2003 2:31 am
Location: Sofia, Bulgaria

Postby Corsix » Thu Jul 29, 2004 3:11 am

damyan wrote:Also I feel myself ashamed by the absence of any comments in my entry

Code: Select all
#pragma warning(disable : 4786) // Not in damyan's code but inserted for MSVC++ 6 users
// A few include files:
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std; // Yepp, we are using the std namespace
// doit will literally do it (the work).
struct doit : map<string, int>{ // based on map<strng, int>
   static iterator i; // Need him later...
   doit() { // The hard work goes on in here...
      // grades is "ABCDE ABCDE ....." - will be used to award grades
      char grades[]="ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE";
      int n; // used for input
      string line; // also used for input
      while(getline(cin, line, '\t')) // Read the name (upto the tab -'\t')
         scanf("%d\n",&n),operator[](line)+=n; // Get the score (scanf) and then add it on to the existing score

      sort(grades, grades+size()); // sort grades to it ends up like "AAABBBCCCDDDEE"

      /* To get the grade we:
      1. sort the grades array: before "ABCDEABCDEABCDEABCDEABCDEABCDE"
                          after  "AAAABBBCCCDDDEEEBCDEABCDEABCDE"
                  
      2. find out how many people have a better score than the current person,
         then, we use that to get the correct grade from the grades array
         eg. if none better then grades[0] -> A. if 5 better then grades[5] -> B.
      */

      for(i = begin();i!=end();i++) // Loop through everyone
         cout << i->first, printf(" scored %d points and was given a grade of %.1s.\n", // Print out name scored ... grade of
            i->second, // print score
            grades+ count_if(begin(), end(), greater)); // get and print grade
   }
   
   static bool greater(value_type x) { // used to get how many people better then the current and thus get grade
      return i->second < x.second;
   }
}_; // note the '_' - it means "doit _;" - makes a doit called _
doit::iterator doit::i; // declare i globally?
int main() {} // an empty main - aww...
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 Bladesniper » Thu Jul 29, 2004 3:48 am

Yes, nice job Ryan!

And nice codes everybody!
User avatar
Bladesniper
 
Posts: 337
Joined: Mon Apr 05, 2004 10:46 am
Location: In your mind.

Postby Guest » Thu Jul 29, 2004 6:06 am

Corsix wrote:I am guessing my program failed because it had "void main()" not "int main()". Becuase when i test it i get perfect results - grr...

No this is why it failed. This is the output I got from your program
beatrice scored 20901 points and was given a grade of C.
carmen scored 18664 points and was given a grade of A.
diana scored 20008 points and was given a grade of D.
esther scored 19521 points and was given a grade of B.
franchesca scored 20849 points and was given a grade of B.
ginny scored 18675 points and was given a grade of A.
heidi scored 21474 points and was given a grade of D.
ilene scored 17782 points and was given a grade of A.
jennifer scored 17554 points and was given a grade of E.
kathryn scored 19245 points and was given a grade of E.
lara scored 21240 points and was given a grade of C.
meredith scored 18714 points and was given a grade of A.
nicole scored 19566 points and was given a grade of D.
ophelia scored 20160 points and was given a grade of B.
patrice scored 19421 points and was given a grade of B.
querida scored 19768 points and was given a grade of C.
rebecca scored 20333 points and was given a grade of B.
shanna scored 17862 points and was given a grade of A.
theresa scored 17857 points and was given a grade of D.
ursula scored 19153 points and was given a grade of E.
veronica scored 17508 points and was given a grade of C.
wilma scored 16849 points and was given a grade of E.
xena scored 18198 points and was given a grade of E.
yvonne scored 19315 points and was given a grade of D.
zoe scored 21071 points and was given a grade of C.
scored 0 points and was given a grade of A.

who scored zero and got an A?
This is from test 6
Guest
 

Postby Corsix » Thu Jul 29, 2004 7:24 am

Anonymous wrote:No this is why it failed. This is the output I got from your program

OK... that isn't the output I get when I compile and run...
Prehaps I should just stop being a bad loser - lol :)
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 Guest » Thu Jul 29, 2004 7:29 am

Corsix wrote:
Anonymous wrote:No this is why it failed. This is the output I got from your program

OK... that isn't the output I get when I compile and run...
Prehaps I should just stop being a bad loser - lol :)

I was not trying to imply anything I was just trying to help. I compiled it with Microsoft Visual Studio .NET 2003 and not sure why that would make any difference.
Guest
 

Postby Ryan » Thu Jul 29, 2004 7:34 am

Alvaro wrote:Thanks for holding the contest, Ryan!

You're quite welcome!

Alvaro wrote:I am very impressed by damyan's code, and by the fact that togra's is pretty much identical to mine.

Yeha, I noticed that too. I had no idea the problem was so compressible. :)

Alvaro wrote:I personally liked the contest about the physical simulation better than this one, but I like the idea of having the program be stdin/stdout based, and this was approachable by a lot more people.

The absolute coolest thing to do would be a contest were two bots would play against each other in some simplified video-game. In the same style as the one with the physics simulation, the organizer would provide a OpenGL-based referee program and perhaps a sample bot. We would submit out bots and they would play a tournament. If the video-game is good enough, we can probably get people from www.gamedev.net interested. Please, post what you think about this.


I had a lot of fun coming up with the simulation one, and I thought it would be a hit. Not many people tried it -- probably because it was too mathy, or maybe because compiling a GLUT program is a little harder.

What you propose is something I've always wanted to do, ever since the days of playing Pascal Robots in high school. :) It would be a significant investment in time, however, and I'm loath to do it without some expectation of participation worthy of such an effort. Appealing to the gamedev.net crowd is a great idea -- that's a large crowd.

Perhaps this is a contest idea that needs input from more than one person, and maybe even code from more than one person. This sounds like it needs further discussion.

Another thing: there area already apps that do this. One is on Garage Games, there's one for Java, there's gamedev.net's attempt, and probably several others. Is there something that we can reuse?
Ryan
Moderator
 
Posts: 323
Joined: Sat Jun 12, 2004 1:34 pm

Postby Ryan » Thu Jul 29, 2004 7:36 am

Corsix: That's the output I got too, on both gcc 3.2.3 and VC++ 2003.
Ryan
Moderator
 
Posts: 323
Joined: Sat Jun 12, 2004 1:34 pm

Postby tomcant » Thu Jul 29, 2004 7:40 am

I would definately participate, providing, like you said, that it is not too mathy and it doesn't take lots of extra programs to make it run, ie. The token program kinda confused some people in my oppinion.
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby Guest » Thu Jul 29, 2004 7:46 am

I am not picking on anyone I am only curious that is all. I hope no one is upset that I used their code like this. I have some questions about the Contest FAQ and Rules.
- May I use global or static variables?
Only if they are declared const. No computed information is to be kept between runs of your solution.

This is from exomo's code
Code: Select all
//and some variables for parsing the input-line
STUDENT new_student;
bool not_sorted;

//vector to store the information of all the students
vector<STUDENT> all_students;

//and some ints for loops and a temporary number
int i, j;

int main()
{
    //read input and sort by name
    while(getline(cin,new_student.name,'\t'))

Is this okay or not?
- May I use switch statements and/or look-up tables?
NO! That is strictly forbidden! We want to see how your algorithm works, but not to see you entered the results! You can create look-up tables during your algorithm is doing its job, but you can't have it entered! Also, you can use switch statements as a help, but not as only and final solution (for example, to enter the results inside).

This from dante code.
Code: Select all
  while( iStudent )
    if( groups[ iGroup ] )
    {
      groups[ iGroup ]--;
      iStudent--;
    }
    else
      iGroup++;
 
  switch( iGroup )
  {
    case 0: return 'A';
    case 1: return 'B';
    case 2: return 'C';
    case 3: return 'D';
    case 4: return 'E';
  } 
}

Is this okay or not?
Guest
 

Postby Dante Shamest » Thu Jul 29, 2004 8:18 am

Code: Select all
  switch( iGroup )
  {
    case 0: return 'A';
    case 1: return 'B';
    case 2: return 'C';
    case 3: return 'D';
    case 4: return 'E';
  } 


I have since modified that code to this.

Code: Select all
return 65+ iGroup;
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Ryan » Thu Jul 29, 2004 8:25 am

Anonymous wrote:I am not picking on anyone I am only curious that is all. I hope no one is upset that I used their code like this. I have some questions about the Contest FAQ and Rules.


I should have been more clear on this. Prior to this contest, all contests were about writing a function -- usually that would be called repeatedly for timing purposes. Look-up tables and static variables were ways of storing answers rather than computing them, and thus were disallowed.

This contest was different. The entire program was written by entrants, and the only thing I (as the judge) cared about was output. Thus those rules were no longer meaningful. I should have talked about that in the contest description, but I overlooked that. Someone did ask about that in the contest thread, and I said there that the rule didn't apply.

I think I may revise the rules when I post the next contest.
Ryan
Moderator
 
Posts: 323
Joined: Sat Jun 12, 2004 1:34 pm

Postby Guest » Thu Jul 29, 2004 8:29 am

Okay thank you Ryan.
Guest
 

Postby Syn » Thu Jul 29, 2004 9:58 am

Doh

666 tokens must have cursed it!!!

Nah it was the do....while(!eof()); progler was having this problem. Do you use DevC++ per chance Ryan?

No worries though :D cheers for the puzzle!!! :wink:
Engineering Student : "How does it work?"
Science Student : "Why does it work?"
Arts Student : "Would you like fries with that?"
User avatar
Syn
 
Posts: 277
Joined: Fri May 14, 2004 3:50 am
Location: Birmingham, UK

Postby exomo » Thu Jul 29, 2004 10:32 am

I liked the contest very much. The results are not very impressing, but I learned a lot about input anyway.

Can anybody tell me why there is a runtime error in my program. I tried it several times on WinXP and it worked perfectly. Now I tried it in Win98 and I get an error after the program has given the correct(!) output.

I guess I shouldn't have changed my last line.
I changed
Code: Select all
for(i=0;i<number;i++)printf("%s scored %i points and was given a grade of %c.\n",all_students[i].name.c_str(),all_students[i].score,all_students[i].grade);

to
Code: Select all
i=-1;
    while(number>i++)printf("%s scored %i points and was given a grade of %c.\n",all_students[i].name.c_str(),all_students[i].score,all_students[i].grade);

this saves 1 token, but it doesn't work correctly.

EDIT:
I just noticed it works with
Code: Select all
i=-1;
    while(number>++i)printf("%s scored %i points and was given a grade of %c.\n",all_students[i].name.c_str(),all_students[i].score,all_students[i].grade);
User avatar
exomo
 
Posts: 894
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest