こんばんは。
2021/3/20に、AtCoderのABC-196に参加しました。
レートは以下の通りとなっています。
A,B問題は解けました。
家の都合で40分ほど遅れて参加し、C問題は間に合いませんでした。
すると、、レートは251→221に低下!ぐあっ。
遅れて参加するのは止めた方が良いのか、A,Bをミスなしで解くだけでは下がってしまうのか、どうなのかな。
A問題
a,b,c,dの4つの数字を入力。
a<x<b、c<y<d が成り立つとき、x-yの最大値を求める。
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int x = 0;
int y = 0;
if(a<b){
x = b;
}else{
x = a;
}
if(c<d){
y = c;
}else{
y = d;
}
System.out.println(x-y);
}
}
B問題
整数または小数 X が与えられるので、小数点以下を切り捨てて整数で出力。
doubleをlong型にしたり、色々考えたのですが、String型にして、'.'が現れるまで1文字ずつ読む方法をとることに。
import java.util.Scanner;
import java.math.BigDecimal;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String x = sc.next();
char flg = '0';
String xs = "";
for(int i=0;i<x.length();i++){
if(x.charAt(i)=='.'){
flg = '1';
break;
}else{
xs = xs + String.valueOf(x.charAt(i));
}
}
System.out.println(xs);
}
}
感想
レートが落ちてしまい、気持ちも落ち込んでいますが、次回もがんばるぞ!!