feat: add pset1
This commit is contained in:
parent
ac31ecc509
commit
f7f679c291
@ -1,124 +0,0 @@
|
||||
<?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>
|
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/pset0.iml" filepath="$PROJECT_DIR$/pset0.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/psets.iml" filepath="$PROJECT_DIR$/psets.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
29
labs/cs2040s/psets/src/demos/rankproblem.java
Normal file
29
labs/cs2040s/psets/src/demos/rankproblem.java
Normal file
@ -0,0 +1,29 @@
|
||||
package demos;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class rankproblem {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int teams = sc.nextInt(); int matches = sc.nextInt(); sc.nextLine();
|
||||
|
||||
ArrayList<Integer> result = new ArrayList<Integer>();
|
||||
for (int i = 1; i <=teams; i++) {
|
||||
result.add(i);
|
||||
}
|
||||
|
||||
while(matches-- > 0) {
|
||||
String[] line = sc.nextLine().split(" ");
|
||||
int i = Integer.parseInt(line[0].substring(1));
|
||||
int j = Integer.parseInt(line[1].substring(1));
|
||||
int n = result.indexOf(i);
|
||||
int m = result.indexOf(j);
|
||||
|
||||
if (n > m) {
|
||||
result.remove(m);
|
||||
result.add(n, j);
|
||||
}
|
||||
}
|
||||
result.forEach(t -> System.out.print("T" + t + " "));
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemA {
|
@ -1,3 +1,4 @@
|
||||
package pset0;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemB {
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemC {
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemE {
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemH {
|
@ -1,3 +1,5 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package pset0;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProblemJ {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scann er(System.in);
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int a = sc.nextInt();
|
||||
int b = sc.nextInt();
|
||||
int c = sc.nextInt();
|
70
labs/cs2040s/psets/src/pset1/falcondive.java
Normal file
70
labs/cs2040s/psets/src/pset1/falcondive.java
Normal file
@ -0,0 +1,70 @@
|
||||
package pset1;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class falcondive {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
|
||||
PrintWriter pw = new PrintWriter(System.out);
|
||||
String[] nums = bi.readLine().split(" ");
|
||||
int M = Integer.parseInt(nums[0]);
|
||||
int N = Integer.parseInt(nums[1]);
|
||||
char c = nums[2].strip().charAt(1);
|
||||
|
||||
char[][] frame1 = new char[M][N];
|
||||
char[][] frame2 = new char[M][N];
|
||||
|
||||
for (int y = 0; y < M; y++) {
|
||||
frame1[y] = bi.readLine().toCharArray();
|
||||
}
|
||||
bi.readLine();
|
||||
for (int y = 0; y < M; y++) {
|
||||
frame2[y] = bi.readLine().toCharArray();
|
||||
}
|
||||
|
||||
int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
|
||||
boolean b = false;
|
||||
|
||||
for (int y = 0; y < M; y++) {
|
||||
if (b) {
|
||||
break;
|
||||
}
|
||||
for (int x = 0; x < N; x++) {
|
||||
if (frame1[y][x] == c) {
|
||||
if (x1 == -1) {
|
||||
x1 = x;
|
||||
y1 = y;
|
||||
}
|
||||
}
|
||||
if (frame2[y][x] == c) {
|
||||
if (x2 == -1) {
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
}
|
||||
}
|
||||
if (x1 != -1 && x2 != -1) {
|
||||
b = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int deltaX = x2 - x1, deltaY = y2 - y1;
|
||||
for (int y = 0; y < M; y++) {
|
||||
for (int x = 0; x < N; x++) {
|
||||
if (x - deltaX < 0 || y - deltaY < 0 || x - deltaX >= N || y - deltaY >= M) {
|
||||
} else {
|
||||
if (frame2[y - deltaY][x - deltaX] == c) {
|
||||
pw.print(c);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pw.print(frame1[y][x] != c ? frame1[y][x] : frame2[y][x]);
|
||||
}
|
||||
pw.println();
|
||||
}
|
||||
pw.flush();
|
||||
}
|
||||
}
|
67
labs/cs2040s/psets/src/pset1/tenis.java
Normal file
67
labs/cs2040s/psets/src/pset1/tenis.java
Normal file
@ -0,0 +1,67 @@
|
||||
package pset1;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class tenis {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String[] names = sc.nextLine().split(" ");
|
||||
int federer = Arrays.asList(names).indexOf("federer");
|
||||
int numMatches = Integer.parseInt(sc.nextLine());
|
||||
while (numMatches-- > 0) {
|
||||
System.out.println(handleMatch(sc.nextLine(), federer) ? "da" : "ne");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean handleMatch(String match, int federer) {
|
||||
int[][] sets = Arrays.stream(match.split(" ")).map(s -> Arrays.stream(s.split(":")).mapToInt(Integer::parseInt).toArray()).toArray(int[][]::new);
|
||||
if (sets.length > 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int left = 0, right = 0;
|
||||
for (int i = 0; i < sets.length; i++) {
|
||||
if (i == 2) {
|
||||
// handle condition where set 3 is not needed to be played
|
||||
if (left == 2 || right == 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int[] sorted = Arrays.stream(sets[i]).sorted().toArray();
|
||||
int a = sorted[0], b = sorted[1];
|
||||
if (i < 2 && b > 7) {
|
||||
return false;
|
||||
}
|
||||
if ((b - a >= 2 && b >= 6) || (i <= 1 && (a == 6 && b == 7))) {
|
||||
if (sets[i][0] > sets[i][1]) {
|
||||
left++;
|
||||
} else {
|
||||
right++;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (left < 2 && right < 2) {
|
||||
return false;
|
||||
}
|
||||
if (left > 2 || right > 2) {
|
||||
return false;
|
||||
}
|
||||
if (federer == -1) {
|
||||
return true;
|
||||
}
|
||||
if (federer == 0 && right > 0) {
|
||||
return false;
|
||||
}
|
||||
if (federer == 1 && left > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user