diff --git a/bin/Main.class b/bin/Main.class index 3ec49de..5ecfc8f 100644 Binary files a/bin/Main.class and b/bin/Main.class differ diff --git a/exercise/src/Main.class b/exercise/src/Main.class index 2eeb10c..117df1e 100644 Binary files a/exercise/src/Main.class and b/exercise/src/Main.class differ diff --git a/exercise/src/Main.java b/exercise/src/Main.java index 17094df..8ec5a42 100644 --- a/exercise/src/Main.java +++ b/exercise/src/Main.java @@ -1,16 +1,48 @@ import java.util.Scanner; +import java.util.HashMap; +import java.util.Map; +import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); - String s = in.nextLine(); - String[] words = s.split(" "); - StringBuilder sb = new StringBuilder(s.length()); - for (int i = words.length - 1; i >= 0; i--) { - sb.append(words[i]); - if (i > 0) sb.append(' '); + if (!in.hasNext()) { + System.out.print("no"); + in.close(); + return; } - System.out.println(sb.toString()); + int n = Integer.parseInt(in.next()); + if (n <= 0) { + System.out.print("no"); + in.close(); + return; + } + + Map cnt = new HashMap<>(); + Map first = new HashMap<>(); + String best = null; + int bestCount = 0; + int bestIdx = Integer.MAX_VALUE; + int idx = 0; + while (idx < n && in.hasNext()) { + String raw = in.next(); + String norm = new BigInteger(raw).toString(); + int c = cnt.getOrDefault(norm, 0) + 1; + cnt.put(norm, c); + if (!first.containsKey(norm)) + first.put(norm, idx); + int fi = first.get(norm); + if (best == null || c > bestCount || (c == bestCount && fi < bestIdx)) { + best = norm; + bestCount = c; + bestIdx = fi; + } + idx++; + } + if (best == null) + System.out.print("no"); + else + System.out.print(best); in.close(); } } \ No newline at end of file diff --git a/作业/作业/刘航宇-day40/第一题/Main.java b/作业/作业/刘航宇-day40/第一题/Main.java new file mode 100644 index 0000000..0f71f1e --- /dev/null +++ b/作业/作业/刘航宇-day40/第一题/Main.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String s = in.nextLine(); + String[] words = s.split(" "); + String best = ""; + int max = -1; + for (String w : words) { + int end = w.length(); + while (end > 0 && !Character.isLetter(w.charAt(end - 1))) end--; + String t = w.substring(0, end); + if (t.length() > max) { + max = t.length(); + best = t; + } + } + System.out.println(best); + in.close(); + } +} \ No newline at end of file diff --git a/作业/作业/刘航宇-day40/第一题/image.png b/作业/作业/刘航宇-day40/第一题/image.png new file mode 100644 index 0000000..5f5af48 Binary files /dev/null and b/作业/作业/刘航宇-day40/第一题/image.png differ diff --git a/作业/作业/刘航宇-day40/第三题/Main.java b/作业/作业/刘航宇-day40/第三题/Main.java new file mode 100644 index 0000000..2e5cc36 --- /dev/null +++ b/作业/作业/刘航宇-day40/第三题/Main.java @@ -0,0 +1,47 @@ +import java.util.Scanner; +import java.util.HashMap; +import java.util.Map; +import java.math.BigInteger; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + if (!in.hasNext()) { + System.out.print("no"); + in.close(); + return; + } + int n = Integer.parseInt(in.next()); + if (n <= 0) { + System.out.print("no"); + in.close(); + return; + } + Map cnt = new HashMap<>(); + Map first = new HashMap<>(); + String best = null; + int bestCount = 0; + int bestIdx = Integer.MAX_VALUE; + int idx = 0; + while (idx < n && in.hasNext()) { + String raw = in.next(); + String norm = new BigInteger(raw).toString(); + int c = cnt.getOrDefault(norm, 0) + 1; + cnt.put(norm, c); + if (!first.containsKey(norm)) + first.put(norm, idx); + int fi = first.get(norm); + if (best == null || c > bestCount || (c == bestCount && fi < bestIdx)) { + best = norm; + bestCount = c; + bestIdx = fi; + } + idx++; + } + if (best == null) + System.out.print("no"); + else + System.out.print(best); + in.close(); + } +} \ No newline at end of file diff --git a/作业/作业/刘航宇-day40/第三题/image.png b/作业/作业/刘航宇-day40/第三题/image.png new file mode 100644 index 0000000..ef9db86 Binary files /dev/null and b/作业/作业/刘航宇-day40/第三题/image.png differ diff --git a/作业/作业/刘航宇-day40/第二题/Main.java b/作业/作业/刘航宇-day40/第二题/Main.java new file mode 100644 index 0000000..1d6cd84 --- /dev/null +++ b/作业/作业/刘航宇-day40/第二题/Main.java @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int n = Integer.parseInt(in.nextLine().trim()); + StringBuilder out = new StringBuilder(); + StringBuilder line = new StringBuilder(); + int count = 0; + while (count < n && in.hasNext()) { + String w = in.next(); + count++; + if (line.length() == 0) { + line.append(w); + } else if (line.length() + 1 + w.length() <= 80) { + line.append(' ').append(w); + } else { + out.append(line).append('\n'); + line.setLength(0); + line.append(w); + } + } + if (line.length() > 0) out.append(line); + System.out.print(out.toString()); + in.close(); + } +} \ No newline at end of file diff --git a/作业/作业/刘航宇-day40/第二题/image.png b/作业/作业/刘航宇-day40/第二题/image.png new file mode 100644 index 0000000..0755f7e Binary files /dev/null and b/作业/作业/刘航宇-day40/第二题/image.png differ diff --git a/作业/压缩包/刘航宇-day40.zip b/作业/压缩包/刘航宇-day40.zip new file mode 100644 index 0000000..2617846 Binary files /dev/null and b/作业/压缩包/刘航宇-day40.zip differ