Loading

加载过慢可尝试刷新

【题解】洛谷 AT1898 ピアニスト高橋君 题解

洛谷题目传送门 | AT 原题传送门

一道简单的打表题。

我们可以把题目给出的 \(12\) 个音所对应的输入字符串先存好,然后直接字符串比对。

然后按照比对结果输出对应的音符即可解决本题。

代码

#include<string>
#include<cstring>
#include<iostream>
using namespace std;
string s,str;
string s1[20]={"","WBWBWWBWBWBW","BWBWWBWBWBWW","WBWWBWBWBWWB","BWWBWBWBWWBW","WWBWBWBWWBWB","WBWBWBWWBWBW","BWBWBWWBWBWW","WBWBWWBWBWWB","BWBWWBWBWWBW","WBWWBWBWWBWB","BWWBWBWWBWBW","WWBWBWWBWBWB"};//输入给出的颜色打表
string s2[20]={"","Do","#Do","Re","#Re","Mi","Fa","#Fa","So","#So","La","#La","Si"};//对应的音符打表
int main()
{
	cin>>s;
    for(int i=0;i<=11;i++)
    {
        str+=s[i];//截取输入前 12 位
    }
    for(int i=1;i<=12;i++)
    {
        if(str==s1[i])//字符串比对
        {
            cout<<s2[i]<<endl;
            return 0;
        }
    }
	return 0;
}
posted @ 2022-08-10 11:32  Makerlife  阅读(2342)  评论(0)    收藏  举报