AtCoder003をやった。
C問題解けそう、後で追記しよう。
C問題解けた!
A
さいころの大きさは与えられた入力値分の面があるということ、
各面の金額は、面番号 * 10000(円)
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(Integer.parseInt(scan.nextLine()));
double kyuryo = 0;
for(int i = 1; i <= list.get(0); i++){
kyuryo += ((double) 10000 * i) / list.get(0);
}
System.out.println((int) kyuryo);
}
}
B
"@"が含まれている文字列があった場合、対抗側の1文字が、"atcoder"に含まれているか否かで判定
含まれているということは差し替えが聞くということで勝利。逆ならば敗北。
文字列は10文字以下
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>();
list.add(scan.nextLine());
list.add(scan.nextLine());
boolean flg = true;
for(int i = 0; i < list.get(0).length(); i++){
if(list.get(0).equals(list.get(1))){
break;
}
if(list.get(0).substring(i, i+1).equals(list.get(1).substring(i, i+1))){
continue;
} else {
if(list.get(0).substring(i, i+1).equals("@") && list.get(1).substring(i, i+1).equals("@")){
System.out.println(i);
continue;
} else if(list.get(0).substring(i, i+1).equals("@")){
flg = "atcoder".contains(list.get(1).substring(i, i+1));
} else if(list.get(1).substring(i, i+1).equals("@")){
flg = "atcoder".contains(list.get(0).substring(i, i+1));
} else if(!list.get(0).substring(i, i+1).equals(list.get(1).substring(i, i+1))){
flg = false;
}
}
if(flg == false){
break;
}
}
if(flg == true){
System.out.println("You can win");
} else if(flg == false){
System.out.println("You will lose");
}
}
}
C
問題文中、レーティングの算出の仕方は記載の通りです。
(C + R) /2
最適(最大値のことかな??)な方法でレーティングを算出せよということなので、途中で昇順ソートした。
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>();
list.add(scan.nextLine());
list.add(scan.nextLine());
int[] numIndex = new int[Integer.parseInt(list.get(0).split(" ")[0])];
for(int i = 0; i < list.get(1).split(" ").length; i++){
numIndex[i] = Integer.parseInt(list.get(1).split(" ")[i]);
}
Arrays.sort(numIndex);
int cnt = numIndex.length - Integer.parseInt(list.get(0).split(" ")[1]);
double sum = 0;
while(cnt < numIndex.length){
sum += numIndex[cnt++];
sum /= 2;
}
System.out.println(sum);
}
}
目指せD問題!