Last active
December 25, 2015 05:59
-
-
Save OrangeCrush/6928816 to your computer and use it in GitHub Desktop.
Solution to ACM programming problem with the test questions. To run this do (unix)
$ javac Main.java && java Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Max F | |
* Run with | |
* $ javac Main.java && java Main | |
* 90 (desired score) | |
* 4 (num exams) | |
* 25 25 25 25 (weight of each) | |
* 80 80 80 (scores on each exam before final) | |
* | |
*/ | |
import java.io.*; | |
public class Main | |
{ | |
public static void main(String[] Args) throws Exception | |
{ | |
//Set up io | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
//Read in the desired score | |
int desired = Integer.parseInt(br.readLine()); | |
//Read in the number of tests in the class | |
int numTests = Integer.parseInt(br.readLine()); | |
//Read in the weights | |
String weights = br.readLine(); | |
String[] weights_ary = weights.split(" "); | |
int[] int_weights = new int[numTests]; | |
for(int i = 0; i < numTests; i++){ | |
int_weights[i] = Integer.parseInt(weights_ary[i]); | |
} | |
//Read in the actual scores | |
String scores = br.readLine(); | |
String[] scores_ary = scores.split(" "); | |
int[] int_scores = new int[numTests]; | |
for(int i = 0; i < numTests - 1; i++){ | |
int_scores[i] = Integer.parseInt(scores_ary[i]); | |
} | |
float weighted_avg = 0; | |
for(int i = 0; i < numTests - 1; i++){ | |
weighted_avg += ((float)int_weights[i] / 100.0 * (float)int_scores[i]); | |
} | |
if(weighted_avg + (int_weights[numTests - 1]) >= desired){ | |
System.out.println(String.format("Score achieved\nYou need a %f", (desired - weighted_avg) / (float)int_weights[numTests - 1] * 100 )); | |
}else{ | |
System.out.println("Can not achieve score."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment