0
0

More than 3 years have passed since last update.

【Java】AtCoderのABC-201に参加しました(レート:264→272)。

Posted at

こんばんは。

2021/5/15に、AtCoderのABC-201に参加しました。
レートは以下の通りとなっています。

image.png

実は家の用事もあり、AB問題を速攻で解いて切り上げてしまいました。
が、C問題についてのミスが発生しなかった?ので、パフォーマンスは高めでした。
嬉しいようないまいちなような。。
順位は5631 / 8739でした。

A問題

3つの数列A1、A2、A3が与えられる。
これを、並べ替えることでA3-A2=A2-A1になるか?
3つしか文字列がないので、2重ループにしてチェックするなり、きれいな書き方は色々あったと思うのですが、とりあえず思いついた実装で。
1,2,3だと、以下の組み合わせがあると考えました。

1
2
3

1
3
2

2
3
1

2
1
3

3
1
2

3
2
1

改めて・・これはセンスないですね。


import java.util.Scanner;

public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
  int a1 = sc.nextInt();
  int a2 = sc.nextInt();
  int a3 = sc.nextInt();

    if((a3-a2)==(a2-a1)||(a2-a3)==(a3-a1)||(a1-a3)==(a3-a2)||(a3-a1)==(a1-a2)||(a2-a1)==(a1-a3)||(a1-a2)==(a2-a3)){
  System.out.println("Yes");
    }else{
  System.out.println("No");
    }
}
}

B問題

N個の山があり、名前はSi、高さはTi。
2番目に高い山の名前を求める。

import java.util.Scanner;

public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  String s[] = new String[n];
  int t[] = new int[n];
  int max1 = 0;
  int maxno = 1001;
  int maxno2 = 1001;
  for(int i=0;i<n;i++){
  s[i] = sc.next();
  t[i] = sc.nextInt();
    if(max1<t[i]){
      max1 = t[i];
      maxno = i;
    }else{
    }
  }  

  max1 = 0;
  for(int i=0;i<n;i++){
    if(max1<t[i]&&i!=maxno){
      max1 = t[i];
      maxno2 = i;
    }else{
    }
  }  

  System.out.println(s[maxno2]);
}
}

最後に

レート維持の目的だけでも、A・Bだけなら15分くらいで解けるようになってきたので、参加は必ずしようと思います。

今後もがんばります!

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