AtCoder001をやった。
URL張り付けてて思ったけど、昔ってAtCoderの各問題の末尾はabcxxx_[数字]なんですね。。
A
引き算によって積雪を求める問題。
単純に1つ目の入力値から2つ目の入力値をひいてあげればよい
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
while (scan.hasNextLine()) {
String str = scan.nextLine();
list.add(str);
}
System.out.println(Integer.parseInt(list.get(0)) - Integer.parseInt(list.get(1)));
}
}
B
問題文に記載のパターンを条件として書き出して、入力値がどれに該当するかを探せばよい。
問題文中にも記載の通り5km より大きく 6km 未満みたいなものは入ってこない。
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<Double> list = new ArrayList<Double>();
list.add(Double.parseDouble(scan.nextLine()) / 1000);
if(list.get(0) < 0.1){
System.out.println("00");
} else if(list.get(0) >= 0.1 && list.get(0) <= 5){
if(list.get(0) * 10 < 10){
System.out.println("0" + Integer.toString((int) (list.get(0) * 10)));
} else {
System.out.println(Integer.toString((int) (list.get(0) * 10)));
}
} else if(list.get(0) >= 6 && list.get(0) <= 30){
System.out.println(Integer.toString((int) (list.get(0) + 50)));
} else if(list.get(0) >= 35 && list.get(0) <= 70){
System.out.println(Integer.toString((int) (list.get(0) - 30) / 5 + 80));
} else {
System.out.println("89");
}
}
}
※本当は変数VVを用意すべきなのかもしれない
C問題いけそうな気がする。
いつかC問題もJavaで解きたいな。