Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo
damyan wrote:Also I feel myself ashamed by the absence of any comments in my entry
#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...#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);}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...
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.
Anonymous wrote:No this is why it failed. This is the output I got from your program
#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);}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
Alvaro wrote:Thanks for holding the contest, Ryan!
Alvaro wrote:I am very impressed by damyan's code, and by the fact that togra's is pretty much identical to mine.
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.
- 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.
//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'))- 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).
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';
}
} switch( iGroup )
{
case 0: return 'A';
case 1: return 'B';
case 2: return 'C';
case 3: return 'D';
case 4: return 'E';
}
return 65+ iGroup;
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.
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);
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);
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);
Users browsing this forum: No registered users and 1 guest