This commit is contained in:
2025-12-15 20:39:50 +08:00
commit c952de8446
201 changed files with 2941 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
# 排除可执行文件
*.out
*.o
# 排除IDE配置文件
.idea/
.vs/
.vscode/
# 排除Trae AI配置文件
.trae/
# 排除编译输出目录
output/
# 排除临时文件
*.tmp
*.temp
# 排除系统文件
.DS_Store
Thumbs.db
# 排除竞赛平台配置文件
.cph/
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+59
View File
@@ -0,0 +1,59 @@
import java.util.Scanner;
public class Main {
static boolean isPrime(int x) {
if (x < 2)
return false;
if (x % 2 == 0)
return x == 2;
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0)
return false;
}
return true;
}
static boolean noZero(String s) {
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == '0')
return false;
return true;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next().trim();
boolean left = false, right = false;
if (noZero(s)) {
boolean ok = true;
for (int i = 0; i < s.length(); i++) {
int v = Integer.parseInt(s.substring(i));
if (!isPrime(v)) {
ok = false;
break;
}
}
left = ok;
}
if (noZero(s)) {
boolean ok = true;
for (int i = s.length(); i >= 1; i--) {
int v = Integer.parseInt(s.substring(0, i));
if (!isPrime(v)) {
ok = false;
break;
}
}
right = ok;
}
if (left && right)
System.out.println("both");
else if (left)
System.out.println("left");
else if (right)
System.out.println("right");
else
System.out.println("false");
in.close();
}
}
@@ -0,0 +1,18 @@
import java.util.Scanner;
public class DivideNum {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = 0;
System.out.println("请输入一个非负三位整数:");
num = in.nextInt();
int hundreds = num / 100;
int tens = (num / 10) % 10;
int units = num % 10;
System.out.println(hundreds);
System.out.println(tens);
System.out.println(units);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

@@ -0,0 +1,14 @@
import java.util.Scanner;
public class ca {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double r = 0;
r= in.nextDouble();
double S_fang = r * r;
double S_yuan = 3.14 * (r * r)/4;
double S_ca = S_fang - S_yuan;
System.out.println("面积差是:" + S_ca);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

@@ -0,0 +1,40 @@
import java.util.Scanner;
public class max {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入三个整数,以空格分隔: ");
int a, b, c;
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
int min = a;
if (b < min) {
min = b;
}
if (c < min) {
min = c;
}
int result;
if (a != max && a != min) {
result = a;
} else if (b != max && b != min) {
result = b;
} else {
result = c;
}
System.out.println("第二小值是: " + result);
in.close();
}
}
@@ -0,0 +1,61 @@
import java.util.Scanner;
public class Num {
private static int min_m(int n, int m) {
int result = n - (m * (m - 1) / 2);
// 分子≤0 或 无法被m整除 → 不满足条件
if (result <= 0 || result % m != 0) {
return -1;
}
// 返回连续序列的首项a(正整数)
return result / m;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入n:");
int n = in.nextInt();
// 防止输入错误
if (n < 1 || n > 10000) {
System.out.println("无符合条件的连续正整数序列");
System.out.println("n应该在1-10000之间");
in.close();
return;
}
boolean found = false;
int m = 2;
int firstnum = -1;
// 从m=2开始寻找,找到第一个满足条件的m就停止
for (m = 2; m <= 150; m++) {
int sum_m = m * (m - 1) / 2;
// 如果n小于等于前m-1个数的和,说明m太大
if (n <= sum_m) {
break;
}
firstnum = min_m(n, m);
if (firstnum != -1) {
found = true;
break;
}
}
if (found) {
System.out.print(n + "=");
for (int i = 0; i < m; i++) {
System.out.print(firstnum + i);
if (i < m - 1) {
System.out.print("+");
}
}
}
else {
System.out.println("无符合条件的连续正整数序列");
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

@@ -0,0 +1,23 @@
import java.util.Scanner;
public class shiyi {
private static int f(int n) {
if (n == 1) {
return 1;
}
if (n == 2) {
return 1;
}
return 2*f(n-2)+f(n-1);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入一个整数n");
int n = in.nextInt();
int result = f(n);
System.out.println(result);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

@@ -0,0 +1,36 @@
import java.util.Scanner;
public class perfect {
private static boolean isPerfect(int n) {
if (n <= 1) {
return false;
}
int sum = 1;
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
sum += i;
int other = n / i;
if (other != i && other != n) {
sum += other;
}
}
}
return sum == n;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入一个数字: ");
int n = in.nextInt();
for (int i = 2; i <= n; i++) {
if (isPerfect(i)) {
System.out.println(i);
}
}
in.close();
}
}
@@ -0,0 +1,28 @@
public class Circle {
private double r;
// ! 构造方法,用于初始化半径
public Circle(double r) {
this.r = r;
}
// ! 计算圆的面积
public double GetArea() {
return Math.PI * r * r;
}
// ! 计算圆的周长
public double GetPerimeter() {
return 2 * Math.PI * r;
}
// ! 获取圆的半径
public double GetRadius() {
return r;
}
// ! 设置圆的半径
public void SetRadius(double r) {
this.r = r;
}
}
@@ -0,0 +1,22 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入圆的半径: ");
String line = in.nextLine();
// 兼容终端管道可能插入的不可见字符,保留数字和符号
line = line.replaceAll("[^0-9.+-]", "");
double radius = Double.parseDouble(line);
// 创建一个半径可输入的圆对象
Circle circle = new Circle(radius);
// 输出圆的面积和周长
System.out.printf("圆的面积: %.2f\n", circle.GetArea());
System.out.printf("圆的周长: %.2f\n", circle.GetPerimeter());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

@@ -0,0 +1,58 @@
public class Employee {
private String name;
private String gender;
private String birthDate;
private double salary;
// 无参构造方法
public Employee() {}
// 带参构造方法
public Employee(String name, String gender, String birthDate, double salary) {
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthDate() {
return birthDate;
}
public void setBirthDate(String birthDate) {
this.birthDate = birthDate;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
// 显示员工信息的方法
public void displayInfo() {
System.out.println("员工信息:");
System.out.println("姓名:" + name);
System.out.println("性别:" + gender);
System.out.println("出生日期:" + birthDate);
System.out.printf("工资:%.2f元\n", salary);
}
}
@@ -0,0 +1,31 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 创建Employee对象
Employee employee = new Employee();
// 输入员工信息
System.out.print("请输入员工姓名:");
employee.setName(in.nextLine());
System.out.print("请输入员工性别:");
employee.setGender(in.nextLine());
System.out.print("请输入出生日期(格式:YYYY-MM-DD):");
employee.setBirthDate(in.nextLine());
System.out.print("请输入工资:");
employee.setSalary(in.nextDouble());
// 输出空行分隔
System.out.println();
// 输出员工信息
employee.displayInfo();
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,15 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入一个整数(表示秒数):");
int t = in.nextInt();
Time time = new Time();
time.Set(t);
System.out.print("转换后的时间是:");
time.Display();
in.close();
}
}
@@ -0,0 +1,32 @@
public class Time {
private int h;
private int m;
private int s;
// 构造方法
public Time() {
this.h = 0;
this.m = 0;
this.s = 0;
}
// 带参构造方法
public Time(int h, int m, int s) {
this.h = h;
this.m = m;
this.s = s;
}
// 将时间转换为总秒数
public void Set(int t) {
this.h = t / 3600;
this.m = (t % 3600) / 60;
this.s = t % 60;
}
// 显示时间,格式为hh:mm:ss
public void Display() {
// 使用String.format确保每位数字占两位,不足补零
System.out.printf("%02d:%02d:%02d\n", h, m, s);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

@@ -0,0 +1,30 @@
import java.util.Scanner;
public class LHY_Compare {
// 重载的compare方法示例
public static int compare() {
return 0;
}
// 比较两个整数,返回较大的值
public static int compare(int a, int b) {
if (a > b) {
return a;
} else if (a < b) {
return b;
} else {
return 0; // 相等时返回0
}
}
// 比较两个字符,返回ASCII码差值的绝对值
public static int compare(char a, char b) {
return Math.abs(a - b);
}
// 比较两个字符串,返回较大的字符串(按字典序)
public static String compare(String a, String b) {
return (a.compareTo(b) > 0) ? a : b;
}
}
@@ -0,0 +1,30 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 读取整数输入
System.out.println("请输入两个整数:");
int num1 = in.nextInt();
int num2 = in.nextInt();
// 调用重载方法并输出结果
System.out.println(LHY_Compare.compare(num1, num2));
// 读取字符输入
System.out.println("请输入两个字符:");
char char1 = in.next().charAt(0);
char char2 = in.next().charAt(0);
// 调用重载方法并输出结果
System.out.println(LHY_Compare.compare(char1, char2));
// 读取字符串输入
System.out.println("请输入两个字符串:");
String str1 = in.next();
String str2 = in.next();
// 调用重载方法并输出结果
System.out.println(LHY_Compare.compare(str1, str2));
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

@@ -0,0 +1,16 @@
public class Airplane extends Vehicle {
private double flightHeight;
public Airplane(String name, double flightHeight) {
super(name);
this.flightHeight = flightHeight;
}
@Override
public void travelInfo() {
System.out.println("交通工具:飞机(" + name + "");
System.out.println("乘坐信息:飞行高度" + flightHeight + "米,适合长途旅行");
System.out.println("特点:速度快,效率高");
System.out.println("------------------------");
}
}
@@ -0,0 +1,16 @@
public class Car extends Vehicle {
private int maxSpeed;
public Car(String name, int maxSpeed) {
super(name);
this.maxSpeed = maxSpeed;
}
@Override
public void travelInfo() {
System.out.println("交通工具:汽车(" + name + "");
System.out.println("乘坐信息:最高时速" + maxSpeed + "km/h,适合短途旅行");
System.out.println("特点:灵活方便,点对点运输");
System.out.println("------------------------");
}
}
@@ -0,0 +1,26 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Vehicle car = new Car("特斯拉Model S", 250);
Vehicle train = new Train("复兴号高铁", 16);
Vehicle airplane = new Airplane("波音747", 12500);
// 调用各交通工具的方法
System.out.println("=== 交通工具乘坐信息 ===");
System.out.println();
car.start();
car.travelInfo();
train.start();
train.travelInfo();
airplane.start();
airplane.travelInfo();
in.close();
}
}
@@ -0,0 +1,17 @@
public class Train extends Vehicle {
private int carriageCount;
public Train(String name, int carriageCount) {
super(name);
this.carriageCount = carriageCount;
}
@Override
public void travelInfo() {
System.out.println("交通工具:火车(" + name + "");
System.out.println("乘坐信息:" + carriageCount + "节车厢,适合中长途旅行");
System.out.println("特点:运量大,准时可靠");
System.out.println("------------------------");
}
}
@@ -0,0 +1,15 @@
public abstract class Vehicle {
public String name;
public Vehicle(String name) {
this.name = name;
}
// 抽象方法,子类必须实现
public abstract void travelInfo();
// 具体方法,子类可以继承
public void start() {
System.out.println(name + "开始启动...");
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

@@ -0,0 +1,5 @@
public interface DbDriver {
void connect(); // 连接数据库方法
void executeQuery(); // 执行查询方法
void disconnect(); // 断开连接方法
}
@@ -0,0 +1,17 @@
public class GoogleDriver implements DbDriver {
@Override
public void connect() {
System.out.println("Google云数据库驱动:建立云端连接...");
}
@Override
public void executeQuery() {
System.out.println("Google云数据库驱动:执行分布式查询");
}
@Override
public void disconnect() {
System.out.println("Google云数据库驱动:关闭云连接");
System.out.println("------------------------");
}
}
@@ -0,0 +1,17 @@
public class IBMDriver implements DbDriver {
@Override
public void connect() {
System.out.println("IBM数据库驱动:建立安全连接...");
}
@Override
public void executeQuery() {
System.out.println("IBM数据库驱动:执行高性能查询操作");
}
@Override
public void disconnect() {
System.out.println("IBM数据库驱动:安全断开连接");
System.out.println("------------------------");
}
}
@@ -0,0 +1,37 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 使用接口的多态:同一调用输出不同内容
UserDriver userDriver = new UserDriver();
// 使用接口类型声明变量
IBMDriver IBMDriver = new IBMDriver();
GoogleDriver GoogleDriver = new GoogleDriver();
// 使用IBM驱动
System.out.println("=== 测试IBM数据库驱动 ===");
userDriver.setDriver(IBMDriver);
userDriver.useDriver();
// 使用Google驱动
System.out.println("=== 测试Google数据库驱动 ===");
userDriver.setDriver(GoogleDriver);
userDriver.useDriver();
// 演示多态特性
System.out.println("=== 多态特性演示 ===");
DbDriver[] drivers = {
new IBMDriver(),
new GoogleDriver()
};
for (DbDriver driver : drivers) {
userDriver.setDriver(driver);
userDriver.useDriver();
}
in.close();
}
}
@@ -0,0 +1,19 @@
public class UserDriver {
private DbDriver driver;
// 设置使用的驱动
public void setDriver(DbDriver driver) {
this.driver = driver;
}
// 使用驱动执行操作
public void useDriver() {
if (driver != null) {
driver.connect();
driver.executeQuery();
driver.disconnect();
} else {
System.out.println("未设置数据库驱动!");
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.nextLine(); // 读取一行输入
int count = 0;
// 遍历字符串中的每个字符
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (Character.isDigit(c)) {
// 检查字符是否为数字
count++;
}
}
// 输出数字字符个数
System.out.println(count);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,45 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String s = "A1B2C3D4E5F6G7H8";
int[] nums = extractInts(s);
String[] letters = extractLetters(s);
System.out.println(Arrays.toString(nums));
System.out.println(Arrays.toString(letters));
}
// 提取数字到 int[]
public static int[] extractInts(String s) {
List<Integer> list = new ArrayList<>();
// 遍历字符串,提取数字字符
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isDigit(c)) {
list.add(c - '0');
}
}
// 将 List<Integer> 转换为 int[]
int[] arr = new int[list.size()];
for (int i = 0; i < list.size(); i++)
arr[i] = list.get(i);
return arr;
}
// 提取字母到 String[]
public static String[] extractLetters(String s) {
List<String> list = new ArrayList<>();
// 遍历字符串,提取字母字符
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isLetter(c)) {
list.add(String.valueOf(c).toUpperCase());
}
}
return list.toArray(new String[0]);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,21 @@
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
public class Main {
// 使用 Map 统计字符串数组中各元素出现次数
public static Map<String, Integer> count(String[] arr) {
Map<String, Integer> freq = new LinkedHashMap<>(); // 保持键的插入顺序
for (String s : arr) {
freq.put(s, freq.getOrDefault(s, 0) + 1);
}
return freq;
}
public static void main(String[] args) {
String[] input = { "a", "b", "a", "b", "c", "a", "b", "c", "b" };
Map<String, Integer> result = count(input);
System.out.println("输入: " + Arrays.toString(input));
System.out.println("统计结果: " + result); // 期望 {a=3, b=4, c=2}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,25 @@
public class Complex {
public int real;
public int imag;
public Complex(int real, int imag) {
this.real = real;
this.imag = imag;
}
public Complex add(Complex other) {
return new Complex(this.real + other.real, this.imag + other.imag);
}
public Complex sub(Complex other) {
return new Complex(this.real - other.real, this.imag - other.imag);
}
// 输出形如 8+6i 或 8-6i
@Override
public String toString() {
String sign = imag >= 0 ? "+" : "-";
int absImag = Math.abs(imag);
return real + sign + absImag + "i";
}
}
@@ -0,0 +1,87 @@
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ComplexCalc {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine().trim();
in.close();
// 支持三种输入:
// 1) "3 2 + 5 4" -> (3+2i) op (5+4i)
// 2) "32 + 54" -> (3+2i) op (5+4i)
// 3) "3+2i + 5+4i" -> 常见复数格式(运算符两侧有空格)
ParseResult pr = parse(line);
if (pr == null) {
System.out.println("输入格式不正确");
return;
}
Complex a = pr.left;
Complex b = pr.right;
Complex res = pr.op == '+' ? a.add(b) : a.sub(b);
System.out.println(res.toString());
}
static class ParseResult {
Complex left;
Complex right;
char op; // '+' or '-'
ParseResult(Complex l, Complex r, char o) { left = l; right = r; op = o; }
}
private static ParseResult parse(String line) {
// 尝试格式1a b op c d
String[] tokens = line.split("\\s+");
if (tokens.length == 5 && isSign(tokens[2])) {
try {
int r1 = Integer.parseInt(tokens[0]);
int i1 = Integer.parseInt(tokens[1]);
int r2 = Integer.parseInt(tokens[3]);
int i2 = Integer.parseInt(tokens[4]);
return new ParseResult(new Complex(r1, i1), new Complex(r2, i2), tokens[2].charAt(0));
} catch (NumberFormatException ignored) {}
}
// 尝试格式2:ab op cd(各为两个数字)
if (tokens.length == 3 && isSign(tokens[1]) && tokens[0].matches("\\d{2}") && tokens[2].matches("\\d{2}")) {
int r1 = tokens[0].charAt(0) - '0';
int i1 = tokens[0].charAt(1) - '0';
int r2 = tokens[2].charAt(0) - '0';
int i2 = tokens[2].charAt(1) - '0';
return new ParseResult(new Complex(r1, i1), new Complex(r2, i2), tokens[1].charAt(0));
}
// 尝试格式3a+bi op c+di(运算符两侧必须有空格)
if (line.contains(" + ") || line.contains(" - ")) {
char op = line.contains(" + ") ? '+' : '-';
String[] parts = line.split("\\s+[+\\-]\\s+");
if (parts.length == 2) {
Complex left = parseAPlusBi(parts[0]);
Complex right = parseAPlusBi(parts[1]);
if (left != null && right != null) {
return new ParseResult(left, right, op);
}
}
}
return null;
}
private static boolean isSign(String s) {
return s.length() == 1 && (s.charAt(0) == '+' || s.charAt(0) == '-');
}
private static Complex parseAPlusBi(String s) {
s = s.trim();
Matcher m = Pattern.compile("^([+-]?\\d+)\\s*([+\\-])\\s*([+-]?\\d+)i$").matcher(s);
if (m.matches()) {
int r = Integer.parseInt(m.group(1));
int sign = m.group(2).charAt(0) == '-' ? -1 : 1;
int i = sign * Integer.parseInt(m.group(3));
return new Complex(r, i);
}
return null;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@@ -0,0 +1,18 @@
import java.util.Scanner;
public class DateApp {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine().trim(); // 形如 2020-10-10
in.close();
String[] parts = line.split("-");
int y = Integer.parseInt(parts[0]);
int m = Integer.parseInt(parts[1]);
int d = Integer.parseInt(parts[2]);
MyDate date = new MyDate();
date.set(y, m, d);
date.print();
}
}
@@ -0,0 +1,16 @@
public class MyDate {
private int year;
private int month;
private int day;
public void set(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
public void print() {
System.out.println("输出重置后的时间:");
System.out.println(year + ":" + month + ":" + day);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,37 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 5x5
int Shuzu[][] = new int[5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
Shuzu[i][j] = in.nextInt();
}
}
// m n
int m, n;
m = in.nextInt();
n = in.nextInt();
//
int temp[]=new int[5];
for (int j = 0; j < 5; j++) {
temp[j] = Shuzu[m][j];
Shuzu[m][j] = Shuzu[n][j];
Shuzu[n][j] = temp[j];
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(Shuzu[i][j] + " ");
}
System.out.println();
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

@@ -0,0 +1,18 @@
import java.util.Scanner;
public class DateApp {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine().trim(); // 形如 2020-10-10
in.close();
String[] parts = line.split("-");
int y = Integer.parseInt(parts[0]);
int m = Integer.parseInt(parts[1]);
int d = Integer.parseInt(parts[2]);
MyDate date = new MyDate();
date.set(y, m, d);
date.print();
}
}
@@ -0,0 +1,16 @@
public class MyDate {
private int year;
private int month;
private int day;
public void set(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
public void print() {
System.out.println("输出重置后的时间:");
System.out.println(year + ":" + month + ":" + day);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,36 @@
import java.util.Scanner;
public class MaxNum {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int max = 0;
if (a>=b)
{
if (a>=c)
{
max = a;
}
else
{
max = c;
}
}
else
{
if (b>=c)
{
max = b;
}
else
{
max = c;
}
}
System.out.println("max="+max);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

@@ -0,0 +1,29 @@
import java.util.Scanner;
public class DaFen {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int score = 0;
if (n<0 || n>40)
{
System.out.println("做对题目数量有误");
}
else {
if (n <= 10) {
score = n * 6;
System.out.println("score=" + score);
}
if (n > 10 && n <= 20) {
score = 60 + (n - 10) * 2;
System.out.println("score=" + score);
}
if (n > 20) {
score = 80 + (n - 20);
System.out.println("score=" + score);
}
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

@@ -0,0 +1,64 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int rows = 5, cols = 5; // 可灵活调整矩阵大小
int[][] matrix = new int[rows][cols];
System.out.println("请输入" + rows + "×" + cols + "二维数组的元素:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix[i][j] = in.nextInt();
}
}
findSaddlePoints(matrix);
in.close();
}
public static void findSaddlePoints(int[][] matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
boolean found = false;
// 预计算每行的最大值
int[] rowMaxs = new int[rows];
for (int i = 0; i < rows; i++) {
int max = matrix[i][0];
for (int j = 1; j < cols; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
rowMaxs[i] = max;
}
// 预计算每列的最小值
int[] colMins = new int[cols];
for (int j = 0; j < cols; j++) {
int min = matrix[0][j];
for (int i = 1; i < rows; i++) {
if (matrix[i][j] < min) {
min = matrix[i][j];
}
}
colMins[j] = min;
}
// 查找鞍点:行最大值且列最小值
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (matrix[i][j] == rowMaxs[i] && matrix[i][j] == colMins[j]) {
System.out.println("鞍点位置: (" + i + ", " + j + "), 值: " + matrix[i][j]);
found = true;
}
}
}
if (!found) {
System.out.println("未找到鞍点");
}
}
}
@@ -0,0 +1,48 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 存储26个字母的出现次数
int[] frequency = new int[26];
int maxFrequency = 0;
// 读取4行文本并统计频率
for (int i = 0; i < 4; i++) {
String line = scanner.nextLine().toUpperCase();
for (char c : line.toCharArray()) {
if (c >= 'A' && c <= 'Z') {
int index = c - 'A';
frequency[index]++;
if (frequency[index] > maxFrequency) {
maxFrequency = frequency[index];
}
}
}
}
// 绘制垂直直方图
for (int row = maxFrequency; row > 0; row--) {
StringBuilder line = new StringBuilder();
for (int i = 0; i < 26; i++) {
if (frequency[i] >= row) {
line.append("* ");
} else {
line.append(" ");
}
}
// 去除行尾空格后输出
System.out.println(line.toString().replaceAll("\\s+$", ""));
}
// 输出字母行
StringBuilder alphabetLine = new StringBuilder();
for (char c = 'A'; c <= 'Z'; c++) {
alphabetLine.append(c).append(" ");
}
System.out.println(alphabetLine.toString().trim());
scanner.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

@@ -0,0 +1,30 @@
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 处理多组测试数据
while (scanner.hasNextInt()) {
int n = scanner.nextInt();
int[] numbers = new int[n];
// 读取n个整数
for (int i = 0; i < n; i++) {
numbers[i] = scanner.nextInt();
}
// 对数组进行排序
Arrays.sort(numbers);
// 输出排序结果
for (int i = 0; i < n; i++) {
System.out.print(numbers[i] + " ");
}
System.out.println(); // 换行
}
scanner.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,28 @@
import java.util.Scanner;
public class Main {
public static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入一个整数:");
int number = in.nextInt();
if (isPrime(number)) {
System.out.println(number + "是素数");
} else {
System.out.println(number + "不是素数");
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

@@ -0,0 +1,20 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
long res = 1L;
for (int i = 2; i <= n; i++) {
res *= i;
while (res % 10 == 0) {
res /= 10; // 去除产生的0
}
res %= 10000000L; // 保留足够位数避免溢出
}
System.out.println(res % 10);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

@@ -0,0 +1,33 @@
import java.util.Scanner;
public class InsertSorted {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[10]; // 容纳插入后的10个元素
for (int i = 0; i < 9; i++) {
if (sc.hasNextInt()) {
arr[i] = sc.nextInt();
}
}
int x = sc.nextInt(); // 待插入的数字
sc.close();
int pos = 9; // 默认插到末尾
for (int i = 0; i < 9; i++) {
if (x <= arr[i]) {
pos = i;
break;
}
}
for (int i = 9; i > pos; i--) {
arr[i] = arr[i - 1];
}
arr[pos] = x;
for (int i = 0; i < 10; i++) {
System.out.println(arr[i]);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

@@ -0,0 +1,27 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String n = in.next();
int s = in.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n.length(); i++) {
char c = n.charAt(i);
while (s > 0 && sb.length() > 0 && sb.charAt(sb.length() - 1) > c) {
sb.deleteCharAt(sb.length() - 1);
s--;
}
sb.append(c);
}
if (s > 0) {
int newLen = Math.max(0, sb.length() - s);
sb.setLength(newLen);
}
int idx = 0;
while (idx < sb.length() && sb.charAt(idx) == '0') idx++;
String res = idx == sb.length() ? "0" : sb.substring(idx);
System.out.println(res);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

@@ -0,0 +1,34 @@
import java.util.Scanner;
public class Main {
static int gcd(int a, int b) {
a = Math.abs(a);
b = Math.abs(b);
while (b != 0) {
int t = a % b;
a = b;
b = t;
}
return a;
}
static long lcm(int a, int b) {
if (a == 0 || b == 0) return 0L;
int g = gcd(a, b);
long x = (long) a / g;
long y = (long) b;
long res = x * y;
if (res < 0) res = -res;
return res;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int g = gcd(a, b);
long l = lcm(a, b);
System.out.println(g + " " + l);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,32 @@
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int K = in.nextInt();
String s = in.next();
BigInteger[][] dp = new BigInteger[N + 1][K + 2];
for (int i = 1; i <= N; i++) {
dp[i][1] = new BigInteger(s.substring(0, i));
}
for (int p = 2; p <= K + 1; p++) {
for (int i = p; i <= N; i++) {
BigInteger best = null;
for (int j = p - 1; j <= i - 1; j++) {
if (dp[j][p - 1] == null)
continue;
BigInteger seg = new BigInteger(s.substring(j, i));
BigInteger cand = dp[j][p - 1].multiply(seg);
if (best == null || cand.compareTo(best) > 0)
best = cand;
}
dp[i][p] = best;
}
}
BigInteger ans = dp[N][K + 1];
System.out.println(ans == null ? "0" : ans.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@@ -0,0 +1,16 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
final double PI = 3.1415;
for (int i = 0; i < n; i++) {
double r = in.nextDouble();
double area = PI * r * r;
System.out.printf("%.6f\n", area);
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,19 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int m = in.nextInt();
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] == m) cnt++;
}
System.out.println(cnt);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

@@ -0,0 +1,33 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
boolean found = false;
for (int a = 1; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 9; c++) {
if (2 * a + 2 * b + c == n) {
int x = a * 10000 + b * 1000 + c * 100 + b * 10 + a;
System.out.println(x);
found = true;
}
}
}
}
for (int a = 1; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 9; c++) {
if (2 * (a + b + c) == n) {
int y = a * 100000 + b * 10000 + c * 1000 + c * 100 + b * 10 + a;
System.out.println(y);
found = true;
}
}
}
}
if (!found) System.out.println(-1);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

@@ -0,0 +1,23 @@
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int N = in.nextInt();
if (N == 0) break;
int[] req = new int[N];
for (int i = 0; i < N; i++) {
int voters = in.nextInt();
req[i] = voters / 2 + 1;
}
Arrays.sort(req);
int need = N / 2 + 1;
int sum = 0;
for (int i = 0; i < need; i++) sum += req[i];
System.out.println(sum);
}
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

@@ -0,0 +1,14 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int f = 0;
for (int i = 2; i <= n; i++) {
f = (f + 3) % i;
}
System.out.println(f + 1);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

@@ -0,0 +1,21 @@
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.next());
if (n == 0) {
System.out.println(0);
in.close();
return;
}
BigInteger tenPow = BigInteger.TEN.pow(n - 1);
BigInteger eightPow = BigInteger.valueOf(8).pow(n - 1);
BigInteger part1 = BigInteger.valueOf(9).multiply(tenPow);
BigInteger part2 = BigInteger.valueOf(7).multiply(eightPow);
BigInteger res = part1.add(part2).divide(BigInteger.valueOf(2));
System.out.println(res.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,38 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long s1 = 0, s2 = 0, s3 = 0;
String bestId = "";
String bestName = "";
int ba = 0, bb = 0, bc = 0;
int best = -1;
for (int i = 0; i < n; i++) {
String id = in.next();
String name = in.next();
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
s1 += a;
s2 += b;
s3 += c;
int tot = a + b + c;
if (tot > best) {
best = tot;
bestId = id;
bestName = name;
ba = a;
bb = b;
bc = c;
}
}
int avg1 = (int) (s1 / n);
int avg2 = (int) (s2 / n);
int avg3 = (int) (s3 / n);
System.out.println(avg1 + " " + avg2 + " " + avg3);
System.out.println(bestId + " " + bestName + " " + ba + " " + bb + " " + bc);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,37 @@
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
String n = in.next();
int b = in.nextInt();
long value = 0L;
for (int i = 0; i < n.length(); i++) {
char ch = n.charAt(i);
int v;
if (ch >= '0' && ch <= '9') v = ch - '0';
else if (ch >= 'a' && ch <= 'f') v = ch - 'a' + 10;
else if (ch >= 'A' && ch <= 'F') v = ch - 'A' + 10;
else v = 0;
value = value * a + v;
}
if (value == 0) {
System.out.println("0");
in.close();
return;
}
ArrayList<Character> digits = new ArrayList<>();
while (value > 0) {
int r = (int)(value % b);
char d = (char)(r < 10 ? ('0' + r) : ('A' + (r - 10)));
digits.add(d);
value /= b;
}
StringBuilder out = new StringBuilder();
for (int i = digits.size() - 1; i >= 0; i--) out.append(digits.get(i));
System.out.println(out.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

@@ -0,0 +1,32 @@
import java.util.Scanner;
public class Main {
static boolean isPrime(int x) {
if (x < 2) return false;
if (x % 2 == 0) return x == 2;
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0) return false;
}
return true;
}
static boolean isPalin(int x) {
String s = Integer.toString(x);
int i = 0, j = s.length() - 1;
while (i < j) {
if (s.charAt(i++) != s.charAt(j--)) return false;
}
return true;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int cnt = 0;
for (int i = 11; i <= n; i++) {
if (isPrime(i) && isPalin(i)) cnt++;
}
System.out.println(cnt);
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@@ -0,0 +1,15 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] h = new int[10];
for (int i = 0; i < 10; i++) h[i] = in.nextInt();
int reach = in.nextInt();
int limit = reach + 30;
int count = 0;
for (int i = 0; i < 10; i++) if (h[i] <= limit) count++;
System.out.println(count);
in.close();
}
}

Some files were not shown because too many files have changed in this diff Show More