0
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 007をやった(Java)

Posted at

AtCoder Beginner Contest 007をやった。
C問題は幅優先探索なのであとから追記予定です。。。
BFSとかなんか競プロって感じやな・・・

A

法則を見つけてあげてください。
ソース見たらわかるか。。。

import java.util.*;

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

        int num = scan.nextInt();
        if(num == 0){
            System.out.println(num);
        } else {
            System.out.println(num-1);
        }
    }
}

B

入力文字に応じて、出力文字を選定していると面倒なので、"a"か"-1"の出力に絞った。

import java.util.*;

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

        boolean flg = true;
        String str = scan.nextLine();

        if(str.length() == 1 && str.split("")[0].equals("a")){
            flg = true;    
        } else {
            flg = false;
        }

        if(flg == true){
            System.out.println(-1);
        } else {
            System.out.println("a");
        }
    }
}

いつか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