LoginSignup
0
0

More than 5 years have passed since last update.

ABC - 052 - A&B

Last updated at Posted at 2019-03-21

AtCoder ABC 052 A&B

AtCoder - 052

A問題

A*Bの長方形の面積と、C*Dの長方形の面積を比べて大きいほうを出力すればよい。
また、A*B==C*Dの場合はその面積を出力(どちらの長方形の面積でもよい)

    int numA = nextInt();
    int numB = nextInt();
    int numC = nextInt();
    int numD = nextInt();

    out.println(numA * numB > numC * numD ? numA * numB : numC * numD);

B問題

xの最大値を出力する。
xの値は下記操作によって変動する。
文字列Sを頭から走査して、一文字ずつ確認する。
※最終的なxの値ではなく、「xの値がmaxになった時の値」が必要

文字列Sの中に'I'があればx++
文字列Sの中に'D'があればx--


        int numN = nextInt();
        char[] strS = next().toCharArray();

        int x = 0;
        int res = 0;
        for (int i = 0; i < strS.length; i++) {
            if (strS[i] == 'I') {
                x++;
            } else if (strS[i] == 'D') {
                x--;
            }
            //xの値が最大かどうかを調べる。
            res = Math.max(res, x);
        }

        out.println(res);
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