AtCoder Beginner Contest 016をやった。
C問題の解き方が知りたいです。
図に書いて大まかにどのようなこと言っているのかは理解できますが、実装的に同実装すればタイムアウト起きないのか知りたく。
A
問題文に与えられたとおりに実装すれば答えが出ます。
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
System.out.println(scan.nextInt() % scan.nextInt() == 0 ? "YES" : "NO");
}
}
B
問題文に記載の通り出力
両方当てはまるパターン、片方ずつ当てはまるパターン、Nothingみたいな感じでやると綺麗に実装できる
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int A = scan.nextInt();
int B = scan.nextInt();
int C = scan.nextInt();
if(A + B == C && A - B == C){
System.out.println("?");
} else if(A + B == C){
System.out.println("+");
} else if(A - B == C){
System.out.println("-");
} else {
System.out.println("!");
}
}
}