feat: add pset0 solved
This commit is contained in:
parent
812dee2e29
commit
ac31ecc509
29
labs/cs2040s/pset0/.gitignore
vendored
Normal file
29
labs/cs2040s/pset0/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
labs/cs2040s/pset0/.idea/.gitignore
vendored
Normal file
8
labs/cs2040s/pset0/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
labs/cs2040s/pset0/.idea/misc.xml
Normal file
9
labs/cs2040s/pset0/.idea/misc.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
labs/cs2040s/pset0/.idea/modules.xml
Normal file
8
labs/cs2040s/pset0/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/pset0.iml" filepath="$PROJECT_DIR$/pset0.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
124
labs/cs2040s/pset0/.idea/uiDesigner.xml
Normal file
124
labs/cs2040s/pset0/.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
labs/cs2040s/pset0/.idea/vcs.xml
Normal file
6
labs/cs2040s/pset0/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
11
labs/cs2040s/pset0/pset0.iml
Normal file
11
labs/cs2040s/pset0/pset0.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
11
labs/cs2040s/pset0/src/ProblemA.java
Normal file
11
labs/cs2040s/pset0/src/ProblemA.java
Normal file
@ -0,0 +1,11 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemA {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
while (sc.hasNextInt()) {
|
||||
int a = sc.nextInt();
|
||||
System.out.println(a / 4.0);
|
||||
}
|
||||
}
|
||||
}
|
13
labs/cs2040s/pset0/src/ProblemB.java
Normal file
13
labs/cs2040s/pset0/src/ProblemB.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemB {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int nums = Integer.parseInt(sc.nextLine());
|
||||
|
||||
for (int i = 0; i < nums; i++) {
|
||||
int result = Integer.parseInt(sc.nextLine().replaceAll(" ", "")) + Integer.parseInt(sc.nextLine().replaceAll(" ", ""));
|
||||
System.out.println(String.valueOf(result).replaceAll("", " ").trim());
|
||||
}
|
||||
}
|
||||
}
|
9
labs/cs2040s/pset0/src/ProblemC.java
Normal file
9
labs/cs2040s/pset0/src/ProblemC.java
Normal file
@ -0,0 +1,9 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemC {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
if (sc.nextInt() + sc.nextInt() != sc.nextInt()) System.out.println("wrong!");
|
||||
else System.out.println("correct!");
|
||||
}
|
||||
}
|
18
labs/cs2040s/pset0/src/ProblemD.java
Normal file
18
labs/cs2040s/pset0/src/ProblemD.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Collectors;
|
||||
public class ProblemD {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
List<Integer> result = Arrays.stream(sc.nextLine().split("/")).map(Integer::new).collect(Collectors.toList());
|
||||
if (result.get(0) > 12) {
|
||||
System.out.println("EU");
|
||||
}
|
||||
else if (result.get(1) > 12) {
|
||||
System.out.println("US");
|
||||
} else {
|
||||
System.out.println("either");
|
||||
}
|
||||
}
|
||||
}
|
17
labs/cs2040s/pset0/src/ProblemE.java
Normal file
17
labs/cs2040s/pset0/src/ProblemE.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemE {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String data = sc.nextLine();
|
||||
if (data.contains(":)") && data.contains(":(")) {
|
||||
System.out.println("double agent");
|
||||
} else if (data.contains(":)")) {
|
||||
System.out.println("alive");
|
||||
} else if (data.contains(":(")) {
|
||||
System.out.println("undead");
|
||||
} else {
|
||||
System.out.println("machine");
|
||||
}
|
||||
}
|
||||
}
|
19
labs/cs2040s/pset0/src/ProblemF.java
Normal file
19
labs/cs2040s/pset0/src/ProblemF.java
Normal file
@ -0,0 +1,19 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemF {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
sc.nextLine();
|
||||
int[] arr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).map(i -> -i).sorted().map(i -> -i).toArray();
|
||||
int result = 0;
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (i < arr.length / 2) {
|
||||
result += arr[i];
|
||||
continue;
|
||||
}
|
||||
result += arr[i]/2;
|
||||
}
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
14
labs/cs2040s/pset0/src/ProblemG.java
Normal file
14
labs/cs2040s/pset0/src/ProblemG.java
Normal file
@ -0,0 +1,14 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemG {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String result = sc.nextLine();
|
||||
while(result.length() > 1) {
|
||||
result = Arrays.stream(result.split("")).map(Integer::new).filter(i -> i > 0).reduce((a, b) -> a * b).orElseThrow().toString();
|
||||
}
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
24
labs/cs2040s/pset0/src/ProblemH.java
Normal file
24
labs/cs2040s/pset0/src/ProblemH.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemH {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int lectures = 0;
|
||||
int awake = 0;
|
||||
sc.nextLine();
|
||||
String[] result = sc.nextLine().split("");
|
||||
for (String r : result) {
|
||||
if (r.equals("0")) {
|
||||
if (awake == 0) continue;
|
||||
else {
|
||||
awake --;
|
||||
lectures++;
|
||||
}
|
||||
} else {
|
||||
awake = 2;
|
||||
lectures++;
|
||||
}
|
||||
};
|
||||
System.out.println(lectures);
|
||||
}
|
||||
}
|
10
labs/cs2040s/pset0/src/ProblemI.java
Normal file
10
labs/cs2040s/pset0/src/ProblemI.java
Normal file
@ -0,0 +1,10 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemI {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
sc.nextLong();
|
||||
System.out.println(Long.toBinaryString(sc.nextLong()).chars().filter(c -> c == '1').count());
|
||||
}
|
||||
}
|
38
labs/cs2040s/pset0/src/ProblemJ.java
Normal file
38
labs/cs2040s/pset0/src/ProblemJ.java
Normal file
@ -0,0 +1,38 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemJ {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scann er(System.in);
|
||||
int a = sc.nextInt();
|
||||
int b = sc.nextInt();
|
||||
int c = sc.nextInt();
|
||||
int shelves = sc.nextInt();
|
||||
int shelvesCount = 0;
|
||||
int currentShelf = shelves;
|
||||
|
||||
while (a != 0 || b != 0 || c != 0) {
|
||||
if (c > 0 && currentShelf >= 3) {
|
||||
c--;
|
||||
currentShelf -= 3;
|
||||
} else if (b > 0 && currentShelf >= 2) {
|
||||
b--;
|
||||
currentShelf -= 2;
|
||||
} else if (a > 0 && currentShelf >= 1) {
|
||||
a--;
|
||||
currentShelf -= 1;
|
||||
} else {
|
||||
shelvesCount++;
|
||||
currentShelf = shelves;
|
||||
}
|
||||
if (currentShelf == 0) {
|
||||
shelvesCount++;
|
||||
currentShelf = shelves;
|
||||
}
|
||||
}
|
||||
if (currentShelf != shelves) {
|
||||
shelvesCount++;
|
||||
}
|
||||
System.out.println(Math.max(shelvesCount, 2));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user