P5733题目链接
toUpperCase()就行了……
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String str2 = str.toUpperCase();
System.out.println(str2);
scanner.close();
}
}
P5734题目链接
为每个命令编写自己的函数,按要求实现即可……
import java.util.Scanner;
public class Main {
private static String doc = "";
private static void append(String append_doc) {
doc = doc + append_doc;
}
private static void cut(int from, int range) {
doc = doc.substring(from, from+range);
}
private static void insert(int from, String insert_doc) {
String head = doc.substring(0, from);
String rear = doc.substring(from);
doc = head + insert_doc + rear;
}
private static int search(String search_key) {
return doc.indexOf(search_key);
}
private static String getResult(String command) {
String[] arr = command.split(" ");
if (command.startsWith("1")) {
append(arr[1]);
return doc;
} else if (command.startsWith("2")) {
cut(Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
return doc;
} else if (command.startsWith("3")) {
insert(Integer.parseInt(arr[1]), arr[2]);
return doc;
} else {
return Integer.toString(search(arr[1]));
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = Integer.parseInt(scanner.nextLine());
doc = scanner.nextLine();
String[] result = new String[num];
for (int i = 0; i < num; i++) {
result[i] = getResult(scanner.nextLine());
}
scanner.close();
for (String s : result) {
System.out.println(s);
}
}
}
P5735题目链接
C = a + b + c 嘛,每条边长就作差平方开根,大家都懂的OK……
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double x1 = scanner.nextDouble(), y1 = scanner.nextDouble(), x2 = scanner.nextDouble(),
y2 = scanner.nextDouble(), x3 = scanner.nextDouble(), y3 = scanner.nextDouble();
double l1 = Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2));
double l2 = Math.sqrt(Math.pow(x3-x2, 2) + Math.pow(y3-y2, 2));
double l3 = Math.sqrt(Math.pow(x3-x1, 2) + Math.pow(y3-y1, 2));
System.out.printf("%.2f", l1+l2+l3);
scanner.close();
}
}
P5739题目链接
不循环,那就是递归,写个递归的阶乘很水的啦……
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
private static BigInteger calculate_factorial(BigInteger num, BigInteger result) {
if (num.equals(new BigInteger("0"))) {
return new BigInteger("1");
} else if (num.equals(new BigInteger("1"))) {
return result;
} else {
result = result.multiply(num);
return calculate_factorial(num.subtract(new BigInteger("1")), result);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger limit = new BigInteger(scanner.next());
scanner.close();
System.out.println(calculate_factorial(limit, new BigInteger("1")));
}
}