P5709题目链接
有几个点注意下:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt(), t = scanner.nextInt(), s = scanner.nextInt();
if (t == 0) {
System.out.println(0);
return;
}
int temp = (int) Math.ceil((double)s / t);
m -= temp;
if (m < 0) {
System.out.println(0);
} else {
System.out.println(m);
}
scanner.close();
}
}
P5710题目链接
感觉是一个逻辑联结词的使用题,没啥特别的……
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
boolean flag1 = num % 2 == 0, flag2 = num > 4 && num <= 12;
//小A
if (flag1 && flag2) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
//Uim
if (flag1 || flag2) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
//八尾勇
//(flag1 && !flag2) || (!flag1 && flag2)
if (flag1^flag2) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
//正妹
if (!flag1 && !flag2) {
System.out.print(1);
} else {
System.out.print(0);
}
}
}
P5711题目链接
经典闰年判法,膜400为0,不为0就判膜100不为0,不为0就判膜4为0
显然还有其他讲究,但这题就没啥说的了……
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
scanner.close();
if (year % 400 == 0) {
System.out.println(1);
} else if (year % 100 == 0) {
System.out.println(0);
} else if (year % 4 == 0) {
System.out.println(1);
} else {
System.out.println(0);
}
}
}
P5712题目链接
做个字符串拼接就行……
做一下简单的特判就行
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String prev = "Today, I ate ";
String rear = " apple";
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
if (num < 2) {
prev = prev + num + rear;
} else {
prev = prev + num + rear + "s";
}
System.out.println(prev + ".");
}
}