0
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 012をやった(Java)

Posted at

AtCoder Beginner Contest 012をやった。

D問題もパッと見た感じ解けそうな気がするので、明日以降に挑戦したく。
※D問題追記予定

A

入力された二つの値を入れ替える問題

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();

        if(A == B){
            System.out.println(A + " " + B);
        } else {
            System.out.println(B + " " + A);
        }
    }
}

B

時間を秒数に変換する典型的な問題
秒数を与えて適当に変換してくれる時間関数が見つからなかったので、自分で実装

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        String hour = String.format("%02d", N / 3600);
        String minute = String.format("%02d", N % 3600 / 60);
        String second = String.format("%02d", N % 3600 % 60);

        System.out.println(hour.concat(":").concat(minute).concat(":").concat(second));
    }
}

C

九九の合計値から、入力分の差分+1を取って、それの該当する九九の範囲内の計算式を求める問題
結構きれいにかけた。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        N = 2025 - N;
        for(int i = 1; i < 10; i++){
            if(N % i == 0 && N / i < 10){
                System.out.println(i + " x " + N/i);
            }
        }
    }
}
0
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
0
0