AtCoder: ABC049C - 白昼夢を解いてみた/C++
問題は以下の通りです。
コードはACされましたが
自分でも無駄が多いなと思うので,自分なりにスマートにコードを書くことを
お勧めします.
※基本的に私のコードはとりあえず動けばいい脳筋コードです.
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string S;
cin >> S;
reverse(S.begin(),S.end());
//cout << S << endl;
//cout << "S.size():"<<S.size() <<endl;
int index = 0;
while(index < S.size()){
skip:
if(S.substr(index,5) == "maerd"){
index += 5;
if(index >= S.length()){
goto out1;
}
//cout << "index:" <<index << endl;
goto skip;
}
else if(S.at(index) == 'r'){
if(S.substr(index+1,6)== "emaerd"){
index += 7;
if(index >= S.length()){
goto out1;
}
//cout << "index:" <<index << endl;
goto skip;
}
else if(S.substr(index+1,5)== "esare"){
index += 6;
if(index >= S.length()){
goto out1;
}
//cout << "index:" <<index << endl;
goto skip;
}
else{
goto out2;
}
}
else if(S.substr(index,5)=="esare"){
index += 5;
if(index >= S.length()){
goto out1;
}
//cout << "index:" <<index << endl;
goto skip;
}
else{
goto out2;
}
}
out1:
if(index == S.length()){
cout << "YES" << endl;
}
else{
out2:
cout << "NO" << endl;
}
}
文字を逆に読む発想を参考にさせていただきました.
参考にしたものは以下のものです.