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回目)。