This commit is contained in:
2025-12-23 08:01:20 +08:00
parent 43fecdd294
commit 5d09b15326
10 changed files with 135 additions and 7 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
+39 -7
View File
@@ -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<String, Integer> cnt = new HashMap<>();
Map<String, Integer> 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();
}
}
@@ -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();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@@ -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<String, Integer> cnt = new HashMap<>();
Map<String, Integer> 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();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@@ -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();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.