Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/charles/ATM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package charles;

import java.util.Scanner;

class ATM {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int amt = s.nextInt();
double bal = s.nextDouble();
s.close();
if (amt % 5 == 0 && amt < (bal - 0.5)) {
bal = (double) (bal - amt - 0.5);
System.out.printf("%.2f", bal);
} else {
System.out.printf("%.2f", bal);
}
}
}
23 changes: 23 additions & 0 deletions src/charles/EnormousInputTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package charles;

import java.util.Scanner;

class EnormousInputTest {
public static void main(String[] args) {
// setup
Scanner s = new Scanner(System.in);
int numDiv = 0;
// input
int n = s.nextInt(); // number of nums
int k = s.nextInt(); // divby test
for (int i = 0; i < n; i++) {
if (s.nextInt() % k == 0) {
numDiv++;
}
}
// output
System.out.println(numDiv);
// cleanup
s.close();
}
}
29 changes: 29 additions & 0 deletions src/charles/Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package charles;

import java.util.Scanner;

class Factorial {
public static void main(String[] args) {
// setup
Scanner s = new Scanner(System.in);
// input/output
int t = s.nextInt(); // number of values
for (int i = 0; i < t; i++) {
System.out.println(trailingZeros(s.nextInt()));
}
// cleanup
s.close();
}

public static int trailingZeros(int num) {
int exp = 1;
int zeros = 0;
int result;
do {
result = (int) (num / Math.pow(5, exp));
exp++;
zeros += result;
} while (result > 1);
return zeros;
}
}
19 changes: 19 additions & 0 deletions src/charles/LifeTheUniverseAndEverything.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package charles;

import java.util.Scanner;

class LifeTheUniverseAndEverything {
public static void main(String[] args) {
int num;
Scanner s = new Scanner(System.in);

while (true) {
num = s.nextInt();
if (num != 42) {
System.out.println(num);
} else {
System.exit(0);
}
}
}
}
21 changes: 21 additions & 0 deletions src/charles/SmallFactorials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package charles;

import java.math.BigInteger; // needed due to number sizes
import java.util.Scanner;

class SmallFactorials {
public static void main(String[] args) {
// setup
Scanner s = new Scanner(System.in);
// input
int t = s.nextInt(); // test cases
for (int i = 0; i < t; i++) {
int n = s.nextInt();
BigInteger fact = BigInteger.valueOf(1);
for (int j = 1; j <= n; j++) {
fact = fact.multiply(BigInteger.valueOf(j));
}
System.out.println(fact);
}
}
}
43 changes: 43 additions & 0 deletions src/charles/TheLeadGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package charles;

import java.util.Scanner;

class TheLeadGame {
public static void main(String[] args) {
// setup
Scanner s = new Scanner(System.in);
// input
int n = s.nextInt(); // rounds
int[] p1Scores = new int[n];
int[] p2Scores = new int[n];
int[] leads = new int[n];
int[] mLeads = new int[n];
for (int i = 0; i < n; i++) {
p1Scores[i] = s.nextInt();
p2Scores[i] = s.nextInt();
}
// actions
// determines leads
for (int i = 0; i < n; i++) {
leads[i] = p1Scores[i] - p2Scores[i];
mLeads[i] = Math.abs(leads[i]);
}
// determines max lead
int max = 0;
int w = 0;
for (int i = 0; i < n; i++) {
if (mLeads[i] > max) {
max = mLeads[i];
if (leads[i] >= 0) {
w = 1;
} else {
w = 2;
}
}
}
// output
System.out.printf("%d %d", w, max);
// cleanup
s.close();
}
}
30 changes: 30 additions & 0 deletions src/charles/TurboSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package charles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

class TurboSort {
public static void main(String[] args) throws NumberFormatException, IOException {
// setup
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out, true);
// input
int t = Integer.parseInt(in.readLine()); // num items
int[] nums = new int[t]; // array of nums
// actions
/*
* TODO make this faster, it's too slow
*/
for (int i = 0; i < t; i++) {
nums[i] = Integer.parseInt(in.readLine());
}
Arrays.sort(nums); // sorts array
// output
for (int i = 0; i < t; i++) {
System.out.println(nums[i]);
}
}
}