0
0

More than 1 year has passed since last update.

AtCoder231をやった(Java)

Posted at

AtCoder231をやった。
懲りずにjavaで実装。

A

基本的には、double型で変数を宣言して、格納されたデータを割ればよいです。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();

        String str = scan.nextLine();
        list.add(str);

        double d = Double.parseDouble(list.get(0)) / 100;

        System.out.println(d);
    }
}

B

※クソコード注意

文字列が重複していたら、その文字列に紐づくカウントをインクリメントすればよいのでは?と考えました。
Java以外でもMapってキーワードで検索かけると多分出てきます。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        String strIndex[] = new String[1000];

        scan.nextLine();
        int i = 0;
        while (scan.hasNextLine()) {
            strIndex[i] = scan.nextLine();
            i++;
        }

        Map<String, Integer> map = new HashMap<String, Integer>();

        for (String s : strIndex) {
            int v;
            if (map.containsKey(s)) {
                v = map.get(s) + 1;
            } else {
                v = 1;
            }
            map.put(s, v);
        }
        // 適当に1000個配列用意してるからnull格納されたkeyは邪魔
        map.remove(null);

        Integer maxValue = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() > maxValue) {
                maxValue = entry.getValue();
            }
        }

        System.out.println(maxKey);
    }
}

ちなみに今回はC問題までいけました。ただTLEだったので載せないです。
いつか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