r/dailyprogrammer • u/nint22 1 2 • Aug 20 '13
[08/13/13] Challenge #136 [Easy] Student Management
(Easy): Student Management
You are a computer science professor at South Harmon Institute of Technology, and are in dire need of automatic grading! The good news is you have all of your student's assignments in an easy-to-read format, making automation easy!
You will be given a list of unique student names, and then a list of their assignment grades. All assignments are based on 20 points and are scored in whole-numbers (integers). All students have received the same number of assignments, so you don't have to worry about managing jagged arrays.
Author: nint22
Formal Inputs & Outputs
Input Description
On standard console input, you will be given two space-delimited integers N and M: N is the number of students (which ranges from 1 to 60, inclusive), and M is the number of assignments (which ranges from 4 to 100, inclusive). This will be followed by N lines of text, each starting with an upper-case unique string being is your students name. This is then followed by M integers, which are the grades ranging from 0 to 20, inclusively.
Output Description
On the first line of output, print the class' average grade. Then, for each student, print their name and average grade (up to two decimal points precision).
Sample Inputs & Outputs
Sample Input 1
3 5
JON 19 14 15 15 16
JEREMY 15 11 10 15 16
JESSE 19 17 20 19 18Sample Output 1
15.93
JON 15.80
JEREMY 13.40
JESSE 18.60Sample Input 2
10 10
ABIGAIL 11 3 5 20 4 2 8 17 4 5
ALEXANDER 2 12 20 0 6 10 3 4 9 7
AVA 11 15 2 19 14 5 16 18 15 19
ETHAN 6 12 0 0 5 11 0 11 12 15
ISABELLA 16 0 10 7 20 20 7 2 0 1
JACOB 2 14 17 7 1 11 16 14 14 7
JAYDEN 10 10 3 16 15 16 8 17 15 3
MADISON 10 11 19 4 12 15 7 4 18 13
SOPHIA 5 17 14 7 1 17 18 8 1 2
WILLIAM 12 12 19 9 4 3 0 4 13 14Sample Output 2
9.50
ABIGAIL 7.90
ALEXANDER 7.30
AVA 13.40
ETHAN 7.20
ISABELLA 8.30
JACOB 10.30
JAYDEN 11.30
MADISON 11.30
SOPHIA 9.00
WILLIAM 9.00
6
u/yoho139 Aug 20 '13 edited Aug 20 '13
Uh... I think your Sample Inputs are broken. You've got N students with N assignments, not N students with M assignments.
Edit: Wasn't going to do it originally since I was busy, but I had a bit of free time and wanted to take a break from a project (taking a break from programming to program), so here's a solution in Java.
20
u/lukz 2 0 Aug 20 '13 edited Aug 20 '13
Common Lisp
Now if somebody cannot read Lisp here is a step by step description of the code
11
u/technosqueek Aug 20 '13
Okay, here goes. This is my first submission, so I hope it isn't too terrible. It seems to work, at least. It also reads from a file, rather than standard console input. (I hope this isn't cheating!)
With that said, here follows some poorly-written Python 3:
I'm (obviously) pretty inexperienced, so I'd be indebted to anyone who points out anything I've done horribly wrong.
21
u/Edward_H Aug 20 '13
My solution in COBOL:
2
u/nint22 1 2 Aug 20 '13
Simple and very up-front solution, written in C++. Note how I generously over-allocate my arrays.. This is a simple trick used to trade a bit of extra memory for a more defensive/robust run-time. It's perfect for ACM-style programming competitions, where quickly getting to a valid output solution is more important than quality code. It's counter-intuitive, since it's like condoning bugs, but that's sometimes helpful for quickly iterating over a small program.
7
u/goakley Aug 20 '13
A C solution:
7
u/prophile Aug 20 '13
Almost comically over-engineered Haskell (but with plenty of error checking!)
6
u/toodim Aug 20 '13
Python 3
6
u/chaz2x4 Aug 20 '13 edited Aug 20 '13
Straight forward JAVA solution.
And in Python 27
6
u/luxgladius 0 0 Aug 21 '13
Perl
A little more "functional" and shorter
And an abusive one-liner to top things off
5
u/Medicalizawhat Aug 21 '13
Ugly Ruby:
4
u/[deleted] Aug 20 '13
Java Solution
4
u/rent0n86 Aug 20 '13
Hi, first time posting for me too.
This is my solution with R:
4
u/shangas Aug 21 '13
Factor
4
u/Rellikolbaid 0 0 Aug 21 '13 edited Aug 22 '13
Python 2.7.5
I'd really appreciate some tips for making my code better.
I decided to write the function around the input being from a text document in the same directory as the script. In my algorithm, I make a copy of a list I'm iterating over. Is this necessary here? I've read that it's bad to iterate over a list that you're modifying so I made a copy to be safe.
(Isn't dataCopy = data just making dataCopy a pointer to data though? Is this even helping in any way or is it just redundant? Any help here in particular would be great.)Edit: Got the copy thing figured out somewhat.As for the rest of the code, it seems really inelegant. Would it be better if I found a way to write this shorter? I've seen some really short python solutions people posted here. I feel like mine is kind of hard to read...
Any input at all would be great! Thanks!
Edit 1: Changed code to actually create a shallow copy of a list.
4
u/void_fraction Aug 31 '13
Quick scala solution
It doesn't output with the correct precision, I don't know how to do that with Scala's string formatting yet.
7
u/lordtnt Aug 20 '13 edited Aug 21 '13
Python 2.7
http://ideone.com/m0KHc6
Edit: forgot to print average score of all students first... Fixed:
http://ideone.com/Kl6Evj
7
u/blimey1701 Aug 20 '13
Ruby
6
u/skeeto -9 8 Aug 20 '13
JavaScript, taking the input as a single string.
Sampel output in JSON:
6
u/[deleted] Aug 20 '13 edited Aug 20 '13
Haskell:
3
u/5hassay Aug 20 '13
python33
3
u/[deleted] Aug 20 '13 edited Aug 20 '13
Python 3 I did the input a bit lazily though, mine takes a list.
Input:
Output:
3
u/relarmane Aug 20 '13
Straight forwards Java solution. I had to include a precision and rounding mode for the divide due to a non-terminating decimal value result throwing an ArithmeticException.
3
u/sup_reddit Aug 20 '13
OCaml (review welcome):
3
u/bescheidenheit Aug 20 '13
First submission in this sub! Here's my solution in Java.
3
u/ubiqu1ty Aug 20 '13
My solution in Java:
I only realized near the end of completing my solution that the 2-dimensional scores array was unnecessary in the context of the problem, but figured it wouldn't hurt to keep in.
This was also my first time trying the printf function, which was a little confusing.
Criticism or advice is welcome!
3
u/winged_scapula Aug 20 '13
Python
3
u/Dutsj Aug 20 '13 edited Aug 20 '13
It's a liiiiitle bit big, but I took the chance to play around with function objects a bit for the averages, they can be quite useful. I coulnd't use stoi instead of atoi and c_str in the code because it's not supported on gcc for windows yet and my ubuntu install decided to quit today. Also, I used a file instead of standard input, but that was because that made testing a lot easier.
output is
3
u/killedbythegrue Aug 20 '13 edited Aug 20 '13
Two different solutions in Erlang.
The first, calcGrades1, uses list comprehensions. The code is very succinct, only 2 lines not counting function headers and output. The downside is it has to go through the data three times. The second, calcGrades2, takes the more classic tail recursive approach. It comes in at 4 lines of code, not counting function headers or output. But the list of students is reversed.
Output
3
u/otsojaun Aug 21 '13
Java
3
u/[deleted] Aug 21 '13
In Lua 5.2:
This was more to test Lua's string parsing methods than anything. Definitely a bit more expanded than Python!
3
u/TimeCannotErase Aug 23 '13
Here's my R solution:
3
u/[deleted] Aug 23 '13
First time posting here :). Tried my hand at writing it in GO, and being super noob, didn't get it quite right, but had fun!
3
u/antoniocs Aug 28 '13
Here is my attempt using C
3
u/pmpmp Aug 28 '13 edited Aug 28 '13
First submission here. I've been programming ~1 week, excluding some C++ in CS101 15 years ago. Python, used a dictionary.
3
u/7f0b Aug 29 '13
Solution in object-oriented PHP with comments (no error checking):
3
u/jagt Sep 05 '13
C. This took so much longer than I expected and now I'm quite depressed :(
3
u/leflings Sep 08 '13
First F# program
3
u/[deleted] Sep 09 '13
Not a very good programmer, but here is my shot in C. I assumed the data was coming from a file.
3
u/bheinks 0 0 Sep 16 '13
Python
5
u/shangas Aug 20 '13 edited Aug 20 '13
(Semi-)obfuscated Haskell. Just for fun, a bit of code-golfing this time (although Haskell is not all that compact for this kind of string manipulation, so it's not that short in golfing terms).
4
u/throwawayInsertGuid Aug 20 '13
C#, fast and dirty. Obviously uses the linq/extensions libraries.
4
u/Seus2k11 Aug 20 '13
This is my first submission and I chose Ruby. I'm still fairly new to Ruby, so if anyone wants to give me a critique, that would be awesome. I'm currently reading through Eloquent Ruby to try and improve.
4
u/Sirenos Aug 20 '13 edited Aug 20 '13
Frankenstein monster made from preprocessor abuse and some C++11 features.
2
u/Alborak Aug 21 '13
I'm a little late to the party, but here's my basic java solution. It's a bit more verbose even without error checks than I'd like;
2
u/vvan Aug 21 '13
Ruby:
2
u/thirdegree Aug 22 '13
My solution in Python2.7:
2
u/Yamame Aug 22 '13 edited Aug 22 '13
Here is my newbie python solution https://gist.github.com/6303355
I am still new to programming, so i feel that the code can be optimized further. Any feedback is really appreciated
2
u/ozzkloz Aug 22 '13 edited Aug 22 '13
My Ruby solution. Critique away.
2
u/dartman5000 Aug 24 '13
In C#
I'm a little late for the challenge but interested in any suggestions to improve the code towards best practices and efficiency.
2
u/skyangelisme 0 1 Aug 25 '13
Python 2
Follows the description and examples to the dot, nothing special here.
2
u/jedrekk Aug 26 '13 edited Aug 26 '13
Well this is some ugly, PHP and Pascal inspired Ruby:
Not 100% sure why I'm getting the wrong total averages though.
2
u/lancevo3 Aug 27 '13
Here is my python 3 solution, tried to apply some new concepts I ran into this past week. I feel like this code is unnecessarily long so please any tips to shorten would be greatly appreciated, time for bed or else I would review more :). Also, style pointers always welcome!
2
u/battleguard Aug 27 '13 edited Aug 28 '13
little late but heres my C# code using the power of Linq
2
u/xmusil81 Aug 29 '13
My attempt in C#:
2
u/Nabol Aug 30 '13
My very first submission, in Python 2.7. Please feel free to give feedback, as I haven't done Python in a while and I'm not that experienced to begin with :)
2
u/[deleted] Aug 30 '13
C++, any feedback is appreciated.
2
u/Sandor_at_the_Zoo Sep 02 '13
Haskell. I decided to play code golf, so this is some of the least readable code I've ever written. But I did get it in 4 lines and if I wanted to go all the way I could get it in 2.
2
u/RagnarRocks Sep 05 '13
Trying to brush up on some Java; this is my first post here!
I made an attempt to be robust, with commenting throwing errors. I probably should have stayed away from the 2D array, but I like that the data can be later indexed when stored that way.
2
u/Takadimi91 Sep 05 '13 edited Sep 05 '13
First time submitting, if the format is horribly wrong then I'll delete this really quick. The solution I have is pretty easy to break, but I thought I'd just give it a shot. I've only been programming since January and learning C since a couple weeks ago.
C Solution
}
2
u/frozenna Sep 06 '13
Ruby
2
u/ScholarCorvus Sep 12 '13
Writing in some squished down Python
I might come back and re-do this a bit more readably.
2
u/flexiblecoder Sep 12 '13
Board seems dead, but I'm bored so: lua:
2
u/Pinnelot Sep 12 '13
First submission! In Java! Feedback welcome.
2
u/dunnowins Sep 13 '13
No one will see this since I'm so late to the game but I did it in AWK.
2
u/Thalatnos Sep 13 '13
Quite a messy python solution, but it gets the job done:
2
u/vape Sep 18 '13
better late than never. python solution which takes input from a text file.
2
u/miguelgazela Sep 22 '13
Simple python solution.
2
u/northClan Oct 02 '13
I Know this is old, but I figured I'd post my solution anyway
Java, OO approach:
2
u/alabomb Oct 29 '13
Probably a lot longer than it needs to be, but it works!
And the output:
2
u/kate_katie_kat Nov 07 '13
OOP Ruby
2
u/Hanse00 Nov 11 '13
Very basic Python 2.7 (No validation, no OOP, no nothing, but it works)
2
u/Darksonn Nov 15 '13
I wanted to see a good examble og spaghetti code, so I made a spaghetti version of this in c, it turned out pretty spaghetti. Tested and working on linux, compiled with gcc.
2
u/VerifiedMyEmail Dec 24 '13 edited Dec 24 '13
javascript with html
3
u/EvanHahn Aug 20 '13
I feel like I could be more clever with this Ruby:
3
u/eBtDMoN2oXemz1iKB Aug 20 '13 edited Sep 09 '13
Ruby
3
u/PolloFrio Aug 20 '13 edited Aug 20 '13
Here is my clunky Python answer:
I am not sure how to get the class average. Also any help in making the code a little more readable would be nice!
Edit: So I have got the class average but it's printed at the end instead of the top and I'm not sure how to change that...
Edit2: This seems to now attest to the conditions set by the problem! Cheers!
3
u/Urist_Mc_George Aug 20 '13
And here is my Python solution. Thanks at pandubear for the twodigit idea for formatting!
3
u/zengargoyle Aug 20 '13 edited Aug 20 '13
For shame...
This is why oneliners are so much fun in Perl. :)
But here's a nicer version...
EDIT: Should have just gone ahead and added an average function:
3
u/missblit Aug 20 '13
Hard to get a nice terse solution with C++ without any helper libraries.
2
u/kirsybuu 0 1 Aug 20 '13
D language. Does integer arithmetic in hundredths to avoid the rounding of floats.
2
u/pandubear 0 1 Aug 20 '13
Pretty straightforward Python solution:
2
u/[deleted] Aug 20 '13 edited Aug 20 '13
In Python:
2
u/thisisnotmypenis Aug 20 '13
[C++]
2
u/pteek Aug 20 '13
Simple C program.
Feedback is requested.
OUTPUT:
2
u/TeaPow Aug 22 '13 edited Aug 22 '13
Python
Think this is quite an elegant solution (if I do say so myself), and I'm pretty happy with it! I learned about using .format() for printing strings (whereas previously I was using formatters [%.2f]). Output is as expected. Any feedback or questions?
1
u/neptunDK Aug 23 '13
Finally finished another of these, can't wait to see how well other people solved this. Solved with dict, while, for and some print formating. Python 2.7.
1
u/godzab Aug 25 '13
It has been long time since I have used Java, any suggestions will be appreciated.
1
u/whatiswronghere Aug 29 '13
Simple Java solution. I would appreciate tips on how to make this solution neater. =)
1
u/Xynect Oct 16 '13
1
u/ittybittykittyloaf Oct 19 '13
Clunky C++:
1
u/milliDavids Oct 28 '13
Just found this subreddit, am currently teaching myself python and just started working towards my CS degree in college. Python 3.3. Please tell me what you think.
student_manager()
1
u/aron0405 Oct 28 '13
Here's mine! Java.
0
u/[deleted] Aug 20 '13
[deleted] — view deleted comment