init
This commit is contained in:
commit
d6e568c685
17
Read Me.txt
Normal file
17
Read Me.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
Here are my competition programs, I completed 3/5 (+an unworking program that I didnt have time for (#4))
|
||||||
|
All my programs are unmodified sense I originaly codded them so you can see my raw coding skill well working fast and underpressure. The only
|
||||||
|
things I added was the comment to walk you through my thought prosses
|
||||||
|
|
||||||
|
Summary of rules:
|
||||||
|
- Only writen resorces are allowed to be brought in and used
|
||||||
|
- Every file must use file input and standard output (Names correspond (S1.java < S1.txt))
|
||||||
|
- 3 hours to complete as many as possible + only completed programs count
|
||||||
|
- some programs may be rated on efficency
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
- I doubled the second place person's score in the local area.
|
||||||
|
|
||||||
|
UPDATE:
|
||||||
|
- My first two programs recieved full marks and completed every test
|
||||||
|
- My third failed misserably and because I needed a minimum of 40 points (15 points a question)
|
||||||
|
I could not move on to participate at waterloo
|
72
S1.java
Normal file
72
S1.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// Zak Timson
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// Class
|
||||||
|
public class S1 {
|
||||||
|
|
||||||
|
// Main method
|
||||||
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
|
|
||||||
|
// Because numbers will be removed each pass
|
||||||
|
// A dynamic array might be nice
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
|
||||||
|
// Import dummy data from S1.txt
|
||||||
|
final String dir = new File(" ").getAbsolutePath().trim();
|
||||||
|
FileReader fr = new FileReader(dir + "S1.txt");
|
||||||
|
Scanner scan = new Scanner(fr);
|
||||||
|
int k = scan.nextInt();
|
||||||
|
|
||||||
|
// Fill array with required number of people
|
||||||
|
for (int i = 0; i < k; i++) {
|
||||||
|
list.add(String.valueOf(i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an array for the different number of passes
|
||||||
|
// that will be done
|
||||||
|
int m = scan.nextInt();
|
||||||
|
int[] remove = new int[m];
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
remove[i] = scan.nextInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each pass
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
// Remember the size of the dynamic array during this pass
|
||||||
|
int size = list.size();
|
||||||
|
|
||||||
|
// Instead of looping through and testing each number in the array
|
||||||
|
// some preliminary math can determine the exact number of passes
|
||||||
|
// needed to increase the efficiency.
|
||||||
|
for (int x = 0; x < size / remove[i]; x++) {
|
||||||
|
|
||||||
|
/* This next part is where a quarter of the competition went well
|
||||||
|
* I over thought how to solve this bug. Because I am removing,
|
||||||
|
* lets say person 5 and 10, as soon as I remove person 5 person 10
|
||||||
|
* will no longer be in index number 9 but rather 8 as it is shrinking.
|
||||||
|
* After thinking about this for quite some time I decided best to move on
|
||||||
|
* and do problem number 2. After completing that one I cam back and instantly
|
||||||
|
* came up with the idea of filling that space with a String object == "".
|
||||||
|
*/
|
||||||
|
list.remove(((x + 1) * remove[i]) - 1);
|
||||||
|
list.add((x + 1) * remove[i] - 1, "");
|
||||||
|
}
|
||||||
|
// Once every person that needed to be removed is switched for a ""
|
||||||
|
// all objects == "" are removed getting rid of that bug.
|
||||||
|
while (list.indexOf("") != -1) {
|
||||||
|
list.remove(list.indexOf(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output the remainder of the dynamic array
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
System.out.println(list.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
S2.java
Normal file
57
S2.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Zak Timson
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
//Class
|
||||||
|
public class S2 {
|
||||||
|
|
||||||
|
// Main method
|
||||||
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
|
|
||||||
|
// Load in dummy data from file
|
||||||
|
final String dir = new File(" ").getAbsolutePath().trim();
|
||||||
|
FileReader fr = new FileReader(dir + "S2.txt");
|
||||||
|
Scanner scan = new Scanner(fr);
|
||||||
|
|
||||||
|
// Get the number of names (never used this information)
|
||||||
|
String n = scan.nextLine();
|
||||||
|
|
||||||
|
// Get the names from file and split the line into an array by white space
|
||||||
|
String names1 = scan.nextLine();
|
||||||
|
String[] nameSet1 = names1.split(" ");
|
||||||
|
|
||||||
|
// Same as above for second set of names.
|
||||||
|
String names2 = scan.nextLine();
|
||||||
|
String[] nameSet2 = names2.split(" ");
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
boolean flag = true;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (flag) {
|
||||||
|
// Compare names index by index
|
||||||
|
if (nameSet1[counter].equals(nameSet2[counter])) {
|
||||||
|
flag = false; // if two of the same names are found
|
||||||
|
// Stop the program because it failed
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
// Counter to keep track of index
|
||||||
|
// As soon as counter > nameSet1.length it will create an
|
||||||
|
// Index out of bounds error (This allows the flag to stay true)
|
||||||
|
}
|
||||||
|
}catch(Exception e){}
|
||||||
|
|
||||||
|
// Based on whether the program errors out or switches the flag a verdict
|
||||||
|
// can be found
|
||||||
|
if (flag) {
|
||||||
|
System.out.println("good");
|
||||||
|
} else {
|
||||||
|
System.out.println("bad");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
S3.java
Normal file
80
S3.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Zak Timson
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// Class
|
||||||
|
public class S3 {
|
||||||
|
|
||||||
|
// Main method
|
||||||
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
|
|
||||||
|
// Load dummy data
|
||||||
|
final String dir = new File(" ").getAbsolutePath().trim();
|
||||||
|
FileReader fr = new FileReader(dir + "S3.txt");
|
||||||
|
Scanner scan = new Scanner(fr);
|
||||||
|
|
||||||
|
// Get number of tests
|
||||||
|
int tests = scan.nextInt();
|
||||||
|
|
||||||
|
// Create 2D array to hold all of the information
|
||||||
|
int[][] cars = new int[tests][];
|
||||||
|
|
||||||
|
for (int i = 0; i < tests; i++) {
|
||||||
|
int num = scan.nextInt(); // get number of cars in test
|
||||||
|
cars[i] = new int[num]; // initiate
|
||||||
|
// Load cars into array
|
||||||
|
for (int x = 0; x < num; x++) {
|
||||||
|
cars[i][x] = scan.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop until every test is complete
|
||||||
|
for (int i = 0; i < cars.length; i++) {
|
||||||
|
|
||||||
|
// Create two dynamic arrays for the train track and branch track by the lake
|
||||||
|
ArrayList train = new ArrayList();
|
||||||
|
ArrayList branch = new ArrayList();
|
||||||
|
|
||||||
|
// Add all the cars to the track
|
||||||
|
for (int x = (cars[i].length-1); x >= 0; x--) {
|
||||||
|
train.add(cars[i][x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean flag = true;
|
||||||
|
int counter = 1; // If there is only one train left it can be completed so offset of 1 is needed to make if's bellow work
|
||||||
|
// Not error checking for consecutive numbers ex. 1, 2, 5, 3. car 4 is missed.
|
||||||
|
|
||||||
|
// Loop until flag changes
|
||||||
|
while (flag) {
|
||||||
|
// If first car on track is required car
|
||||||
|
if (Integer.parseInt(train.get(0).toString()) == counter){
|
||||||
|
counter++; // Update what car is next required
|
||||||
|
train.remove(0); // remove that car from first position on track
|
||||||
|
} else { // Else move first car onto branch
|
||||||
|
branch.add(0, train.get(0).toString());
|
||||||
|
train.remove(0);
|
||||||
|
}
|
||||||
|
// Check fist car on branch to see if it is the required car
|
||||||
|
if (Integer.parseInt(branch.get(0).toString()) == counter){
|
||||||
|
counter++; // Update counter
|
||||||
|
branch.remove(0); // Remove it
|
||||||
|
}
|
||||||
|
// If there is only 1 car left it is a success
|
||||||
|
if (counter == cars[i].length){
|
||||||
|
flag = false; // Make loop stop
|
||||||
|
System.out.println("Y"); // Output result
|
||||||
|
// If there is nothing left on the main track and the first car on the branch track is
|
||||||
|
// not the required car the test is a failure
|
||||||
|
} else if (train.size() == 0 && Integer.parseInt(branch.get(0).toString()) != counter){
|
||||||
|
flag = false; // Stop loop
|
||||||
|
System.out.println("N"); // Output result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
S4.java
Normal file
68
S4.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// Zak Timson
|
||||||
|
// Uses Tint.java (Object)
|
||||||
|
|
||||||
|
/* I didn't finish this program because I got stuck up on the first program trying to fix a bug so I ran out of time.
|
||||||
|
My thinking behind this problem was making an object for each stain glass piece so I could send the object a
|
||||||
|
location and have it return true or false. and from that I could run that each coordinate through two for loops of
|
||||||
|
the largest x and y and determine whether each point was the right tint level. This is as far as I got but after that
|
||||||
|
I was planning on using this data to make a graph similar to the example given and from that I could make the program
|
||||||
|
realise that point (1,2) and (2,2) are part of the same area. This program does have an error so it doesn't run from what
|
||||||
|
I gather because I ran it for the first time just as the competition ended.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// Class
|
||||||
|
public class S4 {
|
||||||
|
|
||||||
|
// Main method
|
||||||
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
|
|
||||||
|
// Load dummy data
|
||||||
|
final String dir = new File(" ").getAbsolutePath().trim();
|
||||||
|
FileReader fr = new FileReader(dir + "S4.txt");
|
||||||
|
Scanner scan = new Scanner(fr);
|
||||||
|
|
||||||
|
// Load number of pieces
|
||||||
|
int pcs = scan.nextInt();
|
||||||
|
// Load what shade of tint we are looking for
|
||||||
|
int lookFor = scan.nextInt();
|
||||||
|
int counter = 0; // keep track of matches
|
||||||
|
|
||||||
|
// create an array of the pieces of tint glass using my Tint object
|
||||||
|
Tint[] tint = new Tint[pcs];
|
||||||
|
|
||||||
|
// Loop for each piece of tinted glass
|
||||||
|
for (int i = 0; i < tint.length; i++) {
|
||||||
|
String temp = scan.nextLine(); // Get the next line of coordinates
|
||||||
|
String[] stats = temp.split(" "); // Split the coordinates
|
||||||
|
// Create a new Tint object with the coordinates
|
||||||
|
tint[i] = new Tint(Integer.parseInt(stats[0]),
|
||||||
|
Integer.parseInt(stats[1]), Integer.parseInt(stats[2]),
|
||||||
|
Integer.parseInt(stats[3]), Integer.parseInt(stats[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through coordinates
|
||||||
|
for (int x = 0; x < 1000000000; x++){ // X coordinate
|
||||||
|
int totalTint = 0; // Reset the total tint on this coordinate
|
||||||
|
for (int y = 0; y < 1000000000; y++){ // Y coordinate
|
||||||
|
// Test to see if each piece of glass to see if coordinate is present in its area
|
||||||
|
for (int i = 0; i < tint.length; i++){
|
||||||
|
// if it is get the tint and add it to the total tint of that coordinate
|
||||||
|
if (tint[i].within(x, y) == true){
|
||||||
|
totalTint+=tint[i].getTint();
|
||||||
|
}
|
||||||
|
// If the total tint is = to what is being looked for
|
||||||
|
if (totalTint == lookFor){
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(counter); // Output the number of tinted spots
|
||||||
|
}
|
||||||
|
}
|
6
S4.txt
Normal file
6
S4.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
4
|
||||||
|
3
|
||||||
|
11 11 20 15 1
|
||||||
|
13 8 14 17 2
|
||||||
|
17 8 18 17 1
|
||||||
|
12 12 19 13 1
|
31
Tint.java
Normal file
31
Tint.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Class
|
||||||
|
public class Tint {
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
double x1, x2, y1, y2;
|
||||||
|
int tint;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public Tint(int x1, int y1, int x2, int y2, int tint) {
|
||||||
|
this.x1 = x1;
|
||||||
|
this.x2 = x2;
|
||||||
|
this.y1 = y1;
|
||||||
|
this.y2 = y2;
|
||||||
|
this.tint = tint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper to see if coordinate is within bounds of object
|
||||||
|
public boolean within(double x, double y) {
|
||||||
|
boolean flag = false;
|
||||||
|
|
||||||
|
if (x > this.x1 && x < this.x2 && y > this.y1 && y < this.y2)
|
||||||
|
flag = true;
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessor
|
||||||
|
public int getTint() {
|
||||||
|
return this.tint;
|
||||||
|
}
|
||||||
|
}
|
BIN
seniorEn.pdf
Normal file
BIN
seniorEn.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user