Official
A - Traffic Light Editorial
by
A - Traffic Light Editorial
by
harurun4635
Editorial for printing
AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題 A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
信号機の色として現れるのは B Y R の三種類のみです。よって if 文を持ちいて、\(3\) 通りの場合わけをすれば良いです。
C++ では string と char は区別します。 string は " で囲い、 char は ' で囲います。どちらで受け取りおよび判定しても良いですが、揃えるように気をつけてください。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
char c; cin >> c;
if (c == 'B'){
cout << 'Y' << endl;
}else if (c == 'Y'){
cout << 'R' << endl;
}else{
cout << 'B' << endl;
}
}
#include<bits/stdc++.h>
using namespace std;
int main(){
string c; cin >> c;
if (c == "B"){
cout << 'Y' << endl;
}else if (c == "Y"){
cout << 'R' << endl;
}else{
cout << 'B' << endl;
}
}
実装例 (PyPy)
c = input()
if c == "B":
print("Y")
elif c == "Y":
print("R")
else:
print("B")
posted:
last update: