2
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 016をやった(Java)

Posted at

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("!");
        }
    }
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0