0
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 010をやった(Java)

Last updated at Posted at 2021-12-23

AtCoder Beginner Contest 010をやった。
たぶんC問題解けるからのちに追加予定。

A

あだ名をどう求めるかです。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        System.out.println(scan.nextLine().concat("pp"));
    }
}

B

いい方法ないかなーと思ったけど、実践的に考えたら「1 <= 入力値 <= 9」らしいので、パターンで判定した

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int[] num = new int[scan.nextInt()];
        for(int i = 0; i < num.length; i++){
            num[i] = scan.nextInt();
        }
        int cnt = 0;

        for(int i = 0; i < num.length; i++){
            if(num[i] == 2 || num[i] == 4 || num[i] == 8){
                cnt += 1;
            } else if(num[i] == 5){
                cnt += 2;
            } else if(num[i] == 6){
                cnt += 3;
            }
        }

        System.out.println(cnt);
    }
}
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