Official
A - Alloy Editorial by penguinman
\(A,B\) を標準入力から読み取った上で、問題文に書かれている通りの場合分けをして
- \(0 \lt A\) かつ \(B=0\) なら
Gold
- \(A=0\) かつ \(0 \lt B\) なら
Silver
- \(0 \lt A\) かつ \(0 \lt B\) なら
Alloy
と出力すればいいです。
実装例 (Python)
A,B = map(int,input().split())
if 0 < A and B == 0:
print('Gold')
if A == 0 and 0 < B:
print('Silver')
if 0 < A and 0 < B:
print('Alloy')
なお、Python における elif 文や else 文、および C++ における else if 文や else 文を用いるとより簡潔です。
実装例 (Python)
A,B = map(int,input().split())
if 0 < A and B == 0:
print('Gold')
elif A == 0 and 0 < B:
print('Silver')
else:
print('Alloy')
特に、以下のように場合分けをするとコードの長さが更に短くなります。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B; cin >> A >> B;
if(B == 0) cout << "Gold" << endl;
else if(A == 0) cout << "Silver" << endl;
else cout << "Alloy" << endl;
}
posted:
last update: