公式
B - Chord 解説
by
B - Chord 解説
by
cn449
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
与えられた条件にしたがって、\(S\) が ACE
、BDF
、CEG
、DFA
、EGB
、FAC
、GBD
のいずれかと等しいか判定すればよいです。
また、実は長さ \(3\) の文字列 \(S\) について、\(S\) が ACE
、BDF
、CEG
、DFA
、EGB
、FAC
、GBD
のいずれかと等しいことは \(S\) が ACEGBDFAC
の部分文字列であることと同値なのでこの性質を使って判定することもできます。
実装例
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
if (s == "ACE" or s == "BDF" or s == "CEG" or s == "DFA" or s == "EGB" or s == "FAC" or s == "GBD") cout << "Yes\n";
else cout << "No\n";
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
string t = "ACEGBDFAC";
cout << (t.find(s) == string::npos ? "No" : "Yes") << '\n';
}
投稿日時:
最終更新: