Lantanggamer
Lantanggamer
JCHJava Community | Help. Code. Learn.
Created by Lantanggamer on 1/21/2025 in #java-help
Is there a way to optimize my code more?
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

int J = in.nextInt() + 1;
int A = in.nextInt();

ArrayList<Integer>size[] = new ArrayList[3];

for (int i = 0; i < 3; i++) {
size[i] = new ArrayList<>();
}

for (int i = 1; i < J; i++) {
char x = in.next().charAt(0);
if (x == 'S') {
size[0].add(i);
} else if (x == 'M') {
size[1].add(i);
} else {
size[2].add(i);
}
}

ArrayList<Integer>arr[] = new ArrayList[J];

for (int i = 0; i < J; i++) {
arr[i] = new ArrayList<>();
}

for (int i = 0; i < A; i++) {
char x = in.next().charAt(0);
int num = in.nextInt();

if (num < J) {
if (x == 'S') {
arr[num].add(0);
} else if (x == 'M') {
arr[num].add(1);
} else {
arr[num].add(2);
}
}
}

int count = 0;
for (int i = 0; i < 3; i++) {
while (!size[i].isEmpty()) {
if (!arr[size[i].get(0)].isEmpty()) {
Iterator<Integer> iterator = arr[size[i].get(0)].iterator();
while (iterator.hasNext()) {
int adj = iterator.next();
if (adj <= i) {
count++;
iterator.remove();
break;
}
}
}
size[i].remove(0);
}
}

System.out.println(count);

}
}
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

int J = in.nextInt() + 1;
int A = in.nextInt();

ArrayList<Integer>size[] = new ArrayList[3];

for (int i = 0; i < 3; i++) {
size[i] = new ArrayList<>();
}

for (int i = 1; i < J; i++) {
char x = in.next().charAt(0);
if (x == 'S') {
size[0].add(i);
} else if (x == 'M') {
size[1].add(i);
} else {
size[2].add(i);
}
}

ArrayList<Integer>arr[] = new ArrayList[J];

for (int i = 0; i < J; i++) {
arr[i] = new ArrayList<>();
}

for (int i = 0; i < A; i++) {
char x = in.next().charAt(0);
int num = in.nextInt();

if (num < J) {
if (x == 'S') {
arr[num].add(0);
} else if (x == 'M') {
arr[num].add(1);
} else {
arr[num].add(2);
}
}
}

int count = 0;
for (int i = 0; i < 3; i++) {
while (!size[i].isEmpty()) {
if (!arr[size[i].get(0)].isEmpty()) {
Iterator<Integer> iterator = arr[size[i].get(0)].iterator();
while (iterator.hasNext()) {
int adj = iterator.next();
if (adj <= i) {
count++;
iterator.remove();
break;
}
}
}
size[i].remove(0);
}
}

System.out.println(count);

}
}
40 replies
JCHJava Community | Help. Code. Learn.
Created by Lantanggamer on 1/12/2025 in #java-help
JavaFX on Eclipse
I've followed some youtube tutorials to the dot as to setting up JavaFX on Eclipse. Unfortunately, I am unable to get it to work. The error that i am getting is: "Error: Could not find or load main class application.Main Caused by: java.lang.ClassNotFoundException: application.Main"
19 replies