AtCoder Beginner Contest 039:C ピアニスト高橋君
解法
全探索で解ける。
(高橋君がドの上にいたと仮定して、入力とマッチしているか確かめる。
違っていたらレの上に立っていると仮定して・・・をシまで確かめる。)
右20個の情報が与えられるのでド~シまでの鍵盤(WBWBWWBWBWBW)をたくさんとっておくことに注意
C++のコード
#include<iostream> #include<string> int main() { std::string s; std::string pos[] = { "Do", "Re","Mi","Fa","So","La","Si" }; std::cin >> s; std::string kenban = "WBWBWWBWBWBWWBWBWWBWBWBWWBWBWWBWBWBWWBWBWWBWBWBW"; int white = 0; for (int i = 0; i < kenban.length(); i++) { if (kenban.substr(i, 20) == s) break; if (kenban[i] == 'W') white++; } std::cout << pos[white] << std::endl; return 0; }