ACM 2000 輸入三個字元後,按各個字元的ASCⅡ碼從小打到的順序輸出這三個字元。 import java.util.Scanner; public class Lengxc {public static void main(String[] args) {Scanner scanner = n ...
ACM 2000 輸入三個字元後,按各個字元的ASCⅡ碼從小打到的順序輸出這三個字元。
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
String str = scanner.next();
char a = str.charAt(0);
char b = str.charAt(1);
char c = str.charAt(2);
if (a < b) {
if (b < c) {
str = a + " " + b + " " +c;
}else {
if (b > c) {
str = a + " " + c + " " + b;
}else {
str = c + " " + a + " " + b;
}
}
}else {
if (b > c) {
str = c + " " + b + " " + a;
}else {
if (a > c) {
str = b + " " + c + " " + a;
}else {
str = b + " " + a + " " + a;
}
}
}
System.out.println(str);
}
scanner.close();
}
}
ACM 2001 輸入兩點坐標(X1,Y1),(X2,Y2),計算並輸出兩點間的距離。
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
double a = 0;
double b = 0;
a = (x1 - x2) * (x1 - x2) + (y1 - y2) * ( y1 - y2);
b = Math.sqrt(a);
System.out.printf("%.2f",b);
System.out.println();
}
scanner.close();
}
}
ACM 2002 根據輸入的半徑,計算球的體積
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
final double p = 3.1415928;
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
double r = scanner.nextDouble();
double v = 0.0;
v = p * r * r * r * 4 / 3;
System.out.printf("%.3f",v);
System.out.println();
}
scanner.close();
}
}