Contest 39: Autograder

Online C++ programming contests.

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

Postby Alvaro » Fri Jul 23, 2004 11:36 am

Well, back to 201. Sorry for the misinformation.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby exomo » Fri Jul 23, 2004 2:41 pm

Code: Select all
using namespace std;

string s;
getline(cin,s,'\t');



thx, it isn't exactly the best way for me but I was able to make something out of it.

Just one last question: How should we detect the end of input? Can I do it as I like?

PS: tokxx doesn't work so I cant tell you how many tokens my prog has. I just type "tokxx contest39.cpp" and nothing is displayed.
User avatar
exomo
 
Posts: 880
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Kybo Ren » Fri Jul 23, 2004 3:04 pm

I made a batch file to do it for me. Read he output tokxx gives you when you run it with no arguments. Then put a pause at the end of the batch file so you can read it.
Kybo Ren
C++ Beginner
 
Posts: 2049
Joined: Wed Feb 11, 2004 9:28 pm

Postby TheKidder » Fri Jul 23, 2004 7:27 pm

doh! I had confused '\t' with '\r'... :D
w00t!
User avatar
TheKidder
 
Posts: 525
Joined: Mon Nov 24, 2003 7:57 pm
Location: MI

Postby t i l e x » Fri Jul 23, 2004 7:51 pm

Mmm, why are there some names in the list that are repeated ? How should we handle them ?
User avatar
t i l e x
 
Posts: 3604
Joined: Wed Dec 03, 2003 3:59 pm
Location: Québec (Canada)

Postby Dante Shamest » Fri Jul 23, 2004 8:42 pm

why are there some names in the list that are repeated ?


Some students have more than one assignment given to them.

How should we handle them ?


Check if the name already exists, and add the score to that name.
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Dante Shamest » Fri Jul 23, 2004 8:43 pm

PS: tokxx doesn't work so I cant tell you how many tokens my prog has. I just type "tokxx contest39.cpp" and nothing is displayed.


Try tokxx -a contest39.cpp
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Kybo Ren » Fri Jul 23, 2004 9:19 pm

Dante Shamest wrote:
why are there some names in the list that are repeated ?


Some students have more than one assignment given to them.

How should we handle them ?


Check if the name already exists, and add the score to that name.

That's actually exactly what I did.



*WARNING: SPOILER*
I used a map. I simply read, using getline, the line up until a /t. Then, I stored that in a string variable. Then I used fin >> score to read the score into my integer for score. Then I did a fin.ignore(1000,'/n') to ignore everything until the newline, just in case.

Then, I used find() to search for the name, which is my key. If it was equal to the end of the map, it wasn't in the map, so I inserted it. If it WAS in the map, I added score to the key's element.

*END SPOILER*
Kybo Ren
C++ Beginner
 
Posts: 2049
Joined: Wed Feb 11, 2004 9:28 pm

Postby t i l e x » Fri Jul 23, 2004 10:01 pm

Ok, I wasn't sure if I had to add it.
User avatar
t i l e x
 
Posts: 3604
Joined: Wed Dec 03, 2003 3:59 pm
Location: Québec (Canada)

Postby Dante Shamest » Fri Jul 23, 2004 10:47 pm

Kybo_Ren wrote:I used a map.


I used a vector.

I tried using a map, but I couldn't seem to be able to sort it more than once. I know it is automatically sorted when you add items in it, but can you sort it again later on based on some other criteria?
Last edited by Dante Shamest on Sat Jul 24, 2004 5:07 am, edited 1 time in total.
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia

Postby Kybo Ren » Fri Jul 23, 2004 10:57 pm

Why would you want to? I suppose you could using the functions in the <algorithm> header, though.

EDIT: I like the [quote]...[/url], though :p
Kybo Ren
C++ Beginner
 
Posts: 2049
Joined: Wed Feb 11, 2004 9:28 pm

Postby exomo » Sat Jul 24, 2004 12:52 am

Try tokxx -a contest39.cpp


thanks.

I am at 530 now. I use vectors because I don't know maps and all the other stuff you are talking about.
User avatar
exomo
 
Posts: 880
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Kybo Ren » Sat Jul 24, 2004 2:28 am

Maps are soo much easier than vectors...
I took me just a few minutes to learn :)
I think maps are really great. I even made a directory program with them (i.e. an address book).
Kybo Ren
C++ Beginner
 
Posts: 2049
Joined: Wed Feb 11, 2004 9:28 pm

Postby Beer Hunter » Sat Jul 24, 2004 5:53 am

Alvaro wrote:
Code: Select all
getline(cin,s,'\t');
Curse you, Alvaro! Stop giving away our secrets! ;-)
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Corsix » Sat Jul 24, 2004 7:32 am

When you test our code I am assuming that you will feed in the data my calling C:\ myprog < test2.txt or similar. I ask this as my program checks cin.eof to know when input has finished.

EDIT: Will the test2.txt have a newline on the end? (like test1.txt) or will it not? (like the example data in the post)

PS. I'm doing it with 410 tokens

EDIT:
Kybo_Ren wrote:Then I used fin >> score to read the score into my integer for score. Then I did a fin.ignore(1000,'/n') to ignore everything until the newline, just in case.

Umm, shouldn't you be using cin not fin? beacuse fin works with files whereas cin deals with stdin?
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 0 guests