0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoder Beginner Contest 015をやった(Java)

Posted at

AtCoder Beginner Contest 015をやった。
C問題は追記予定です。
できるか正直自信がないところです。

##A
問題文記述の必ず違う数字というところに注意

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String A = scan.nextLine();
        String B = scan.nextLine();
        if(B.length() < A.length()){
            System.out.println(A);
        } else {
            System.out.println(B);
        }
    }
}

##B
入力値で0は計算から除外して考えるらしい。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int zeroCount = 0;
        double[] A = new double[N];
        for(int i = 0; i < N; i++){
            A[i] += scan.nextInt();
            if(A[i] == 0){
                zeroCount++;    
            }
        }
        
        double sum = 0;
        for(int i = 0; i < N; i++){
            sum += A[i];
        }
        sum = sum / (N - zeroCount);
        System.out.println((int) Math.ceil(sum));
    }
}

いつかC問題もJavaで解きたいな(n回目)。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?