ACM 2003 求實數的絕對值 import java.util.Scanner; public class Lengxc { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); wh ...
ACM 2003 求實數的絕對值
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
double d = scanner.nextDouble();
if (d < 0) {
d = -1 * d;
}
System.out.printf("%.2f",d);
System.out.println();
}
scanner.close();
}
}
ACM 2004 輸入一個百分制的成績,將其轉換對應的等級,具體轉換規則如下
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int i = scanner.nextInt();
if (i < 0 || i > 100) {
System.out.println("Score is error!");
} else {
int s = (int) i / 10;
switch (s) {
case 10:
System.out.println("A");
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
}
}
scanner.close();
}
}
ACM 2005 給定一個日期,輸出這個日期是該年的第幾天。輸入格式:yyyy/MM/dd
import java.util.Scanner;
public class Lengxc {
public static void main(String[] args) {
int[] months = {31,28,31,30,31,30,31,31,30,31,30,31};
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
String str = scanner.next();
String[] s = str.split("/");
int year = Integer.parseInt(s[0]);
int month = Integer.parseInt(s[1]);
int day = Integer.parseInt(s[2]);
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
months[1] = 29;
}else {
months[1] = 28;
}
int sum = 0;
for(int i = 0;i < month - 1;i++) {
sum = sum + months[i];
}
sum = sum + day;
System.out.println(sum);
}
scanner.close();
}
}