公式
B - Poisonous Oyster 解説 by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
The answer is as follows:
- If both Takahashi and Aoki got sick:
- The answer is \(1\), which is contained in both \(\{1,2\}\) and \(\{1,3\}\).
- If Takahashi got sick but Aoki did not:
- The answer is \(2\), which is contained in \(\{1,2\}\) but not in \(\{1,3\}\).
- If Aoki got sick but Takahashi did not:
- The answer is \(2\), which is not contained in \(\{1,2\}\) but in \(\{1,3\}\).
- If both Takahashi and Aoki did not get sick:
- The answer is \(4\), which is contained in neither \(\{1,2\}\) nor \(\{1,3\}\).
Thus, we can use if
statements to implement the casework.
For more details on implementation, please refer to the sample code below (C++ and Python).
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
if (s1 == "sick") {
if (s2 == "sick") cout << 1 << endl;
else cout << 2 << endl;
} else {
if (s2 == "sick") cout << 3 << endl;
else cout << 4 << endl;
}
}
Sample code (Python) :
s1, s2 = input().split()
if s1 == "sick":
if s2 == "sick":
print(1)
else:
print(2)
else:
if s2 == "sick":
print(3)
else:
print(4)
投稿日時:
最終更新: