AtCoder ABC 052 A&B
A問題
ABの長方形の面積と、CDの長方形の面積を比べて大きいほうを出力すればよい。
また、AB==CDの場合はその面積を出力(どちらの長方形の面積でもよい)
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);