Giter VIP home page Giter VIP logo

cs130a_prog1's Introduction

Program 1

Problem Overview

Student test scores are streamed on stdin. The first line is a number (k). Each subsequent line consists of a student ID, which is an alphanumeric string without spaces, and an integer between [0-1000]. The input is terminated with 2 newlines. Write a program which takes this input containing test scores and returns the student who has the maximum score averaged across his/her top k tests, followed by a newline. If the student has fewer than k test scores, ignore that student.

For this assignment, you must implement your own heap along with the percolate_up, percolate_down, and build_heap methods. Don't feel obligated to change your naming convention to match this; camelCase is fine, you don't have to use snake_case.

Sample Input

2
bob14 7
steve92 998
bob14 999
skip 1000
steve92 998
bob14 999

(end of file was two empty lines)

Sample Output

bob14

Solution

I created a pair that stores the name of each student as the key, and stores all the corresponding score of that student as the value, I will call the pair student. And each student is stored in a vector called main vector. After finish reading the file, I loop through the main vector and use the build_heap on the score vector of each student, which gives me a max heap. And I'll take the average of the top k score as the maxavg of that student, and use that to compare with the maxavg of other students. Code implementation could be found at the Prog1 folder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.